Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWIdget multiple selection
Qt 6.11 is out! See what's new in the release blog

QListWIdget multiple selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 8.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I have a QListWidget and I have enabling multiple selections using following line

    QListWidget * listWidget =new QListWidget;
    listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);

    What is best way to handle multiple selection in QListWidget I am using following . Let me know if it is best way to do that

    connect(listWIdget,::itemSelectionChanged(), this, handleMultipleSelectionInList())

    handleMultipleSelectionInList() {
    QList<QListWidgetItem *> QListWidget::selectedItems() const

    foreach (QListWidgetItem* item, listWidget->selectedItems())
    QString text = item->data(Qt::UserRole).toString();
    // do necessary processing for text
    }
    }

    is the best way to do that or can some one suggest me the better way to do that

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      That should be the way to go.
      Doesn't it work for you?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Some one in my tool used the following and it was single selectiion
        connect(d_ListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(currentTextChanged(const QString&)));

        sp wanted to check which is the best way

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Well, you cannot change the text in more than one item at the same time. And

          currentTextChanged(const QString&)
          

          is completely different to

          itemSelectionChanged()
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved