PDA

View Full Version : Collapse/Expand button in QTreeViewWidget



Skorpien126
9th June 2010, 17:41
Hello,
I want to write my own selection handling for my QTreeWidget. Unfortunatly the mechanism QT currently provides to do that doesn´t fit my needs. Thats why I created a class inheriting from QTreeWidget. In this class I deactivate (block!) all signals. The capture the for me necessary mouse events by overwriting mousePressEvent(QMouseEvent *event). It´s also possible to get an treeWidgetItem by using the coordinates. So far so good! But now I´m using a hierachical tree containing the collapse/expand button.

My question: How can I found out when the user clicked this button???

QTreeWidgetItem* l_TreeWidgetItem = itemAt(mapFromGlobal(QCursor::pos())) and QModelIndex l_ModelIndex = indexAt(mapFromGlobal(QCursor::pos())) show me what Item/ModelIndex was clicked but this didn´t help me. Any hints I could check out!?!?!

Best regards - Skorpien126

wysota
9th June 2010, 18:04
In this class I deactivate (block!) all signals.
Bad idea. I'd compare it to trying to stop a running car by pouring out all fuel from the fuel tank instead of just using breaks.

Disabling signals effectively disables all functionality of QTreeWidget. What you should do instead (if you really need custom selection handling) is to reimplement the methods responsible for doing the selection or simply handling input events and manipulating the selection model yourself.

Skorpien126
10th June 2010, 07:30
Yeahhh.... you are right regarding this. But this is the only way to catch the events I need. I tried to use an event filter on my inheriting class to catch the mouseClick events. But seems that they are transmitted to the QTreeWidget - object. Something like this doesn´t work. Is there a reason for that??? (edit when I set the eventFilter on the viewPort() I can catch the signals but then the collapsing/expanding doesn´t work anymore)

bool myTreeWidget::eventFilter(QObject *obj, QEvent *event)
{
// handle depending on eventType
switch (event->type())
{
case QEvent::MouseButtonPress:
// handle event for ourself
return true;
break;
...
}
}


Handling the input events is basicly possible and also working. But unfortunately it´s to slow for our purpose!!! We need to handle about 5000 entries in out tree using a "intelligent" selection.


By the way - is there flow chart showing in which order single signals are emitted when I take action (for example click on an item)???

Thx for the input...

wysota
10th June 2010, 12:30
Yeahhh.... you are right regarding this. But this is the only way to catch the events I need.
No. Events and signals don't interfere each other.

If you are subclassing then using event filter on yourself doesn't make sense as you can reimplement required event handlers directly.