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. Get multiselected Indexes of a QListwidget

Get multiselected Indexes of a QListwidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    superkato
    wrote on last edited by
    #1

    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.

    BR
    Sam

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you try this ?

      @QListWidget wid = new QListWidget;
      QList<QListWidgetItem
      > list = wid->selectedItems();
      //Iterate over each item
      // Call
      QListWidgetItem->setSelected(true)@

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • S Offline
        S Offline
        superkato
        wrote on last edited by
        #3

        Hi Dheerandra,

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

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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)list1.at(i);
          qDebug() << " Value ="<<it->text();
          it->setSelected(true);
          }
          @

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          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