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. How to get both index and selected item at asame time in qtreewidget?
Qt 6.11 is out! See what's new in the release blog

How to get both index and selected item at asame time in qtreewidget?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 7.2k 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.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    Hi i have a problem...In my tree widget i wanted to know the selected (actually checked) item index
    for that i used signal
    @connect(ui->treeWidget_FilesSelected,SIGNAL(clicked(QModelIndex)),this,SLOT(GetSelectedSignal(QModelIndex)));
    @

    Now i wanted along with index i needed current item too, for that one more signal i got
    @connect(ui->treeWidget_FilesSelected,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(GetSelectedSignalItm(QTreeWidgetItem*,int)))@

    but i wanted a signal to get index and current item at a same time....how can i do that?
    please help me...i tried in manual but didnt understand how can i get both index and current item at same time...

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You could use a two staged approach, if you really need to have both at the same time.
      Receive the model index through first connection of signal clicked to your slot. Subsequently, you can "retrieve a pointer to your item":http://developer.qt.nokia.com/doc/qt-4.8/qtreewidget.html#currentItem and send the signal with both as you require.
      However, the question is, if you still require to have both sent in a signal.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        this is a two step problem, i think:
        first:
        QTreeWidget::selectedItems ()
        this will return in your case a QList with one item
        and the
        QTreeWidget::indexFromItem ( QTreeWidgetItem * item, int column = 0 ) will get the index for you

        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