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

QTreeView::indexAt works only if Header is invisible

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.4.1
    • Widgets: Itemviews
    • None

    Description

      When using QTreeView::indexAt with a position from mouse pointer, I get wrong results if the Header of the TreeView is visible:

      The indexAt(QPos(10, 10)) result for each of these QTreeViews should be different (at least in my opinion...).

      But both result in a valid QModelIndex:

      QModelIndex(0,0,0x0,QStringListModel(0x21a34deb600))
      QModelIndex(0,0,0x0,QStringListModel(0x21a34deb600))
      

      As a minimal example to reproduce this behaviour, this can be taken:

      #include "QTreeViewTest.h"
      
      #include <QVBoxLayout>
      #include <QTreeView>
      #include <QStringListModel>
      
      
      QTreeViewTest::QTreeViewTest(QWidget *parent)
          : QMainWindow(parent)
      {
          QStringListModel* model = new QStringListModel({ "One", "Two", "Three" }, this);
      
          resize(600, 400);
          
          QWidget* centralWidget = new QWidget(this);
          QVBoxLayout * verticalLayout = new QVBoxLayout(centralWidget);
      
          QTreeView* treeView1 = new QTreeView(centralWidget);
          treeView1->setObjectName("treeView1");
          verticalLayout->addWidget(treeView1);
          treeView1->setModel(model);
      
          QTreeView* treeView2 = new QTreeView(centralWidget);
          treeView2->setObjectName("treeView2");
          verticalLayout->addWidget(treeView2);
          treeView2->setModel(model);
          treeView2->setHeaderHidden(true);
      
          setCentralWidget(centralWidget);
      
          qDebug() << treeView1->indexAt(QPoint(10, 10));
          qDebug() << treeView2->indexAt(QPoint(10, 10));
      }
      

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            SJungherz Steffen Jungherz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: