Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129191

QTreeView on QMainWindow Impossible to Select Row

    XMLWordPrintable

Details

    • Android

    Description

      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 / uncomment 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)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            polla_tosen@yahoo.com Polla Tosen
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes