[SOLVED] How to get selected item on QTreeView ?
-
wrote on 13 Feb 2016, 19:19 last edited by takoo
How to get selected item on QTreeView ?
-
wrote on 13 Feb 2016, 21:30 last edited by
currentIndex() doesn't work?
-
wrote on 13 Feb 2016, 21:55 last edited by
Please give me example code
-
wrote on 13 Feb 2016, 22:05 last edited by Ni.Sumi
Hi @takoo ,
connect(treeWidgetName, SIGNAL(itemSelectionChanged()), this, SLOT(mySlot_Changed()));or
connect(this,SIGNAL(itemClicked(QTreeWidgetItem*, int)), SLOT((mySlot_Changed()));
http://doc.qt.io/qt-4.8/qtreewidget.html#itemSelectionChanged
-
@takoo
Hello,
As @asanka424 suggested, use the available API for the view and the model:QTreeView * view; //< You have that properly set, I'm putting it here for completeness. QModelIndex index = view->currentIndex(); QVariant data = view->model()->data(index); QString text = data.toString();
Kind regards.
-
wrote on 14 Feb 2016, 02:47 last edited by
If you want to get the item use QModelIndex::internalPointer()
-
wrote on 14 Feb 2016, 14:04 last edited by
@kshegunov thanks :D
-
wrote on 14 Feb 2016, 14:49 last edited byThis post is deleted!
5/9