Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt5: QTreeWidget::currentItem() only retuns an item every second call
Violet Giraffe last edited by
Quite a weird problem. I have a QTreeWidget as a part of a more complex custom widget. I'm trying to get current cursor position by calling currentItem(). This happens when I press a global shortcut key. The problem is that currentItem() only returns an item every 2nd time I press the key, otherwise it returns 0. To make sure it's not something I'm doing to the tree widget, I've set up a timer with 1 second interval that calls this slot:
qDebug() << ui->list->currentItem();
And here's what it outputs:
I didn't press any keys and didn't move or click mouse while the timer was working.
I've tried digging into Qt sources with debugger, but only figured out that it's caused by currentIndex() returning default-constructed index.