Important: Please read the Qt Code of Conduct -

QListWIdget multiple selection

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

    QListWidget * listWidget =new QListWidget;

    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

  • Lifetime Qt Champion

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

  • 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

  • Lifetime Qt Champion

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

    currentTextChanged(const QString&)

    is completely different to


Log in to reply