PDA

View Full Version : QTreeWidget click



^NyAw^
24th October 2007, 15:14
Hi,
I'm having a problem with a QTreeWidget.
I've created a class derived from QTreeWidget and I've reimplemented "mouseReleaseEvent" as:


void myTree::mouseReleaseEvent(QMouseEvent* event)
{
QTreeWidgetItem* pqItem = itemAt(event->pos());
emit (emitItemClicked(pqItem));
}


This let me know if the user has clicked into blank space(not an item).

Then, the QWidgetTree automatically selects the clicked item. This works when I was using Qt 4.1.0, but now that I've updated to Qt 4.3.0 this don't work. The item is emmited, but the QTreeWidget sometimes select the item and sometimes don't(there are items to expand with "plus" also).

Maybe have I to force the QTreeWidget to select the item? And, how to know if the user have clicked the "plus" or not?

Thanks,

^NyAw^
24th October 2007, 15:19
Hi,

Well, seems to work:


void myTree::mouseReleaseEvent(QMouseEvent* event)
{
QTreeWidgetItem* pqItem = itemAt(event->pos());
this->setCurrentItem(pqItem);
emit (emitItemClicked(pqItem));
}


Thanks,

^NyAw^
24th October 2007, 16:22
Hi,

mmm, it seems to work when it wants.

jpn
24th October 2007, 16:47
With your code, the base class implementation receives only mouse press and mouse move events, but no mouse release events at all. No wonder if selection (handled by the base classes) is somehow broken.. ;)

You should call the base class implementation so that it doesn't get out of sync:


void myTree::mouseReleaseEvent(QMouseEvent* event)
{
QTreeWidget::mouseReleaseEvent(event);
...
}