Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
4.7.1
-
None
-
MS VS2005 SP1 with hot fixes, Windows XP SP2 with hot fixes.
Description
When using QTreeWidget::itemAt() to get the QTreeWidgetItem at a specific coordinate the itemAt() function returns the wrong item.
I've attached a screenshot which demonstrates the issue.
The code looks like this:
bool VagtDispDlg::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::ContextMenu && (obj == IDLB_DUTIES || obj == IDLB_EMPLOYEES)) { QContextMenuEvent *cmevent = static_cast<QContextMenuEvent*>(event); QTreeWidget *tree = qobject_cast<QTreeWidget*>(obj); if (tree) { QPoint pos = cmevent->pos(); QTreeWidgetItem *twitem = tree->itemAt(pos); PdcVagtdispVagt *vitem = dynamic_cast<PdcVagtdispVagt*>(twitem); if (vitem) { qDebug() << vitem->data(0, Qt::DisplayRole) << pos; } } } return QObject::eventFilter(obj, event); }
As you can see from the screenshot I get data for the third item even though the first is highlighted. It seems as if the actual position of the items in regard to the header isn't taken into consideraton, as I get the data for the first item if I right-click just a pixel inside the QTreeWidget (where the header is).
If this is the correct behaviour then some note should be made in the documentation, along with a way of how to calculate the correct offset for the position of a given item.