QTreeView::indexat returning invalid index for part of very lowest items

  • I've got a QTreeView. For two of the columns, I have code such that the mouse pointer changes to a little hand. Like this:

    @bool AnalysisResultsListDock::eventFilter(QObject* watched, QEvent* event)
    if(event->type() == QEvent::MouseMove)
    auto mouseMoveEvent = dynamic_cast<QMouseEvent*>(event);
    auto position = mouseMoveEvent->globalPos();
    position = ui->treeView->mapFromGlobal(position);
    auto index = ui->treeView->indexAt(position);
    if(index.column() == 1 || index.column() == 2)

    return QDockWidget::eventFilter(watched, event);


    However, when I scroll down to the very bottom of the treeview, and mouse over, the pointer does not change until I am about one and a half lines up (i.e. halfway across one item, it changes).

    Adding breakpoints, it seems that the index being returned from indexAt is invalid when the mouseMove Event is over the pixels taken up by roughly one and a half rows at the bottom of the treeview.

    This makes little sense to me. I didn't write the code, but I can read it and I don't see anything obviously wrong; is there some kind of offset value being calculated wrongly or other such?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.