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. [SOLVED]about get the Index of the SelectedItem on the QTreeWidget
QtWS25 Last Chance

[SOLVED]about get the Index of the SelectedItem on the QTreeWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.3k 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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by
    #1

    there is no way to get the index directly from the SelectedItem?
    i use this way: pSelItemParent->indexOfChild(pSelItem);
    is this the only way?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Binary91
      wrote on last edited by
      #2

      currentIndex() ?

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu
        wrote on last edited by
        #3

        thank you. i'll have a try
        is it equal to the selectedItem's index?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Binary91
          wrote on last edited by
          #4

          If only one item is selected, I think yes, because setting current item also selects it.

          Well, I think you will get problems when having more than one selected item. I think the only way to handle with that is using selectedItems and IndexFromItem:
          @QTreeWidget* treewidget;

          // some code...

          QList<QTreeWidgetItem*> items_selected = treewidget->selectedItems();
          QList<QModelIndex*> indexes_selected;
          for(int i = 0; i < items_selected.count(); i++)
          indexes_selected.append(treewidget->indexFromItem(items_selected.at(i)));@
          (not tested)

          or directly using:
          @treewidget->selectedIndexes():@
          I would also use this method if only one item is selected, you can check that with items_selected.count() if you need this information later. currentItem() is no good way for multi-selections I think.

          Hope that helps you...

          1 Reply Last reply
          0
          • O Offline
            O Offline
            opengpu
            wrote on last edited by
            #5

            thank you very much :)

            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