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



  • 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...


  • Moderators

    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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.