How can I find the selected item in a QTreeWidget?

陌路散爱 提交于 2019-12-03 15:22:56

Using the itemClicked() signal will miss any selection changes made using the keyboard. I'm assuming that's a bad thing in your case.

Dusty is almost correct. But the itemSelectionChanged signal will not tell you which item is selected.

QList<QTreeWidgetItem *> QTreeWidget::selectedItems() const

will give you the selected item(s).

So, connect a slot to the itemSelectionChanged signal, then call selectedItems() on the tree widget to get the selected item(s).

Sofiane

you can simply use this :

QString word = treeWidget->currentItem()->text(treeWidget->currentColumn());

to get your text in the variable word.

According to the documentation here it appears that you should connect the QTreeWidget itemSelectionChanged() signal to a slot in your class. That will tell you which QTreeWidgetItem was selected which is what I believe you want.

ooops, I've solved simply using this:

connect(this,SIGNAL(itemClicked(QTreeWidgetItem*, int)), SLOT(mySlot()));

however thanks for replies :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!