PDA

View Full Version : In QTreeView (and list view) signal when item is double clicked.



paul23
11th February 2012, 21:53
Hi there,

I have a qtreeview (with a model) - Now I wish to execute some code (a slot) when an item in the tree view is double clicked. How can I do this? I'd prefer not having to derive from this treeview - as I'd like keep using the qt designer to design the interface.... Is this possible?

Zlatomir
11th February 2012, 22:13
Double click signal (http://developer.qt.nokia.com/doc/qt-4.8/qabstractitemview.html#doubleClicked)

paul23
12th February 2012, 13:48
ok.... Strange I missed it ><

However how do I use this? I tried doing something like:

void MainInterface::DoubleClickInputTree(const QModelIndex& index) {
QStandardItem * t = reinterpret_cast<QStandardItem *>(index.internalPointer());
auto f(t->font());
f.setBold(true);
t->setFont(f);
}
So on double clicking an item it ought to be "bolded" - however this doesn't seem to work???? - How do I get the item corresponding to the qmodelindex?

EDIT:Nvm lol.. just after posting this I remembered reading "itemfromindex" somewhere so that helped me finding the correct function (auto t(model.itemFromIndex(index))

Lykurg
12th February 2012, 23:00
If you want an item based approach, then use QTreeWidget. There you can use QTreeWidget::itemDoubleClicked() which delivers the item directly to the slot.
If you are using a model, than you have to go via a custom delegate.