View Full Version : QTreeWidget - itemAt(QMousePos): error if there is a header
Phalanx
11th April 2011, 11:24
Hi, I have a problem with QTreeWidget with function itemAt(QMousePos). If there is a header in tree widget then function returns next item. Is it a bug? :confused:
stampede
12th April 2011, 07:56
Post a minimal compilable code reproducing the problem :)
wysota
12th April 2011, 13:00
Hi, I have a problem with QTreeWidget with function itemAt(QMousePos). If there is a header in tree widget then function returns next item. Is it a bug? :confused:
No, it's not a bug. The coordinates are in viewport space not the view space.
Phalanx
15th April 2011, 11:47
Thank you wysota
Phalanx
25th April 2011, 12:15
I can not figured it out.
I use it this way now, but it is not working with header:
// without header works fine
QMouseEvent *MousePos; // where the user clicked
treeWidget->itemAt(MousePos->pos())
// with header, try to get global position but never returns item
QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
QPoint globalPos = ui->treeWidget->viewport()->mapToGlobal(mouseEvent->pos());
QTreeWidgetItem *item = ui->treeWidget->itemAt(globalPos);
fuck, nothing works :mad:
wysota
26th April 2011, 16:17
Why are you trying to get a global position? You don't need a global position but position in the viewport's coordinate space.
This should work:
QPoint pos = ui->treeWidget->viewport()->mapFromParent(event->pos());
or something like that, depending on what is the receiver of the event.
Phalanx
27th April 2011, 19:05
Thank you, that's it :( It tooks me few hours of my life :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.