QTreeView on QMainWindow Impossible to Select Row
-
wrote on 22 Sept 2024, 05:20 last edited by
Please help, this issue is so frustrating, not sure what I am doing wrong.
On Windows, the two examples described below works correctly, but not Example #2 on Android.(I am testing on a Samsung Galaxy S22 Ultra, OS Version: Android 14.0, SDK 34)
Example #1
When showing a QTreeView on Windows and Android, row selection works normal.Example #2
But when the QTreeView is on a QMainWindow, selecting rows on Windows work as expected, but on Android are basically impossible. It seems like the click coordinates are wrongly translated or something. If I click to the top-left of where the QTreeView is, I am almost able to click something, but the behavior is clearly wrong.Please see my code below - comment on the TOGGLE define to switch between Examples #1 and #2 when compiling.
Also attached are screen captures taken on Android to show the issue.#include <QApplication> #include <QMainWindow> #include <QToolBar> #include <QTreeView> #include <QStandardItemModel> // comment or uncomment to toggle between examples #define TOGGLE int main(int argc, char *argv[]) { QApplication app(argc, argv); QStandardItemModel model; model.setHorizontalHeaderLabels({ "Fruit" }); model.setItem(0, new QStandardItem("Apples")); model.setItem(1, new QStandardItem("Grapes")); model.setItem(2, new QStandardItem("Pears")); model.setItem(3, new QStandardItem("Watermelons")); #ifdef TOGGLE // EXAMPLE #1 - row clicks work correctly on Android QTreeView tree; tree.setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows); tree.setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); tree.setModel(&model); tree.showMaximized(); #else // EXAMPLE #2 - row clicks do not work correctly on Android QTreeView *tree = new QTreeView(); tree->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows); tree->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); tree->setModel(&model); QToolBar *toolbar = new QToolBar(); toolbar->addAction("File"); toolbar->addAction("Edit"); toolbar->addAction("View"); toolbar->addAction("Window"); QMainWindow window; window.addToolBar(toolbar); window.setCentralWidget(tree); window.showMaximized(); #endif return app.exec(); }
Screenshot of Example #1 (correct behavior)
Screenshot of Example #2 (incorrect behavior, impossible to correctly select a row)
-
That’s a bug in Qt.
The reproducer is wonderful, thanks! Please file a bug report with that reproducer at https://bugreports.qt.io. -
wrote on 22 Sept 2024, 07:20 last edited by
Thank you, bug logged QTBUG-129191
-
wrote on 27 Sept 2024, 07:11 last edited by
I installed Qt 6.6.3 and and tried my C++ widget application (QList and QLineEdit).
The bugs in 6.7.2 was NOT there. So instead of rewriting in QML I continue with 6.6.3 for Android projects. -
wrote on 8 Oct 2024, 09:12 last edited by
Not solved in 6.8 :(