Important: Please read the Qt Code of Conduct -

Get multiselected Indexes of a QListwidget

  • Hi,

    I have a QListWidget with 8 Items, that the user can multi select.
    I want to store the selected indexes into a variable.

    I need the variables in this format:
    MyIndexes[8] = {0,1,2,3,4} // with getSelectedIndexes

    in the other way I want to load my stored indexes in to the widget (setSelectedIndexes)
    @ui->Mylist = (MyIndexes);

    Can someone please help me?
    I tried but I failed.


  • Qt Champions 2017

    Did you try this ?

    @QListWidget wid = new QListWidget;
    > list = wid->selectedItems();
    //Iterate over each item
    // Call

  • Hi Dheerandra,

    thank you for your reply, could you explain the code to me a little bit please.

  • Qt Champions 2017

    Here is what I said and code snippet as well.

    @ listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);

    qDebug() << "Selected items =" << list1.count();
    for(int i=0;i<list1.count();i++){
    //qDebug() << "I =" << i << endl;
    QListWidgetItem it = (QListWidgetItem);
    qDebug() << " Value ="<<it->text();

Log in to reply