Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QTreeView on QMainWindow Impossible to Select Row

QTreeView on QMainWindow Impossible to Select Row

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 351 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Polla
    wrote on 22 Sept 2024, 05:20 last edited by
    #1

    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_20240922_135935.png

    Screenshot of Example #2 (incorrect behavior, impossible to correctly select a row)
    Screenshot_20240922_134357.png

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 22 Sept 2024, 06:57 last edited by
      #2

      That’s a bug in Qt.
      The reproducer is wonderful, thanks! Please file a bug report with that reproducer at https://bugreports.qt.io.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Polla
        wrote on 22 Sept 2024, 07:20 last edited by
        #3

        Thank you, bug logged QTBUG-129191

        1 Reply Last reply
        2
        • M Offline
          M Offline
          MartinGU
          wrote on 27 Sept 2024, 07:11 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MartinGU
            wrote on 8 Oct 2024, 09:12 last edited by
            #5

            Not solved in 6.8 :(

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved