Unexpected console messages for selection changes in QTreeView
-
I have a QTreeView embedded in a layout structure that resides in a QMainWindow (because I use a QToolBar), which is embedded in a QDockWidget that is docked at the left side of my top-level QMainWindow.
The QTreeView is coming from the Designer.
For demonstration, I initialize it with a QStandardItemModel as follows:QStandardItemModel *model = new QStandardItemModel(); QStandardItem *parentItem = model->invisibleRootItem(); parentItem->appendRow(new QStandardItem("row1")); parentItem->appendRow(new QStandardItem("row2")); parentItem->appendRow(new QStandardItem("row3")); parentItem->child(0)->appendRow(new QStandardItem("subrow11")); parentItem->child(1)->appendRow(new QStandardItem("subrow21")); parentItem->child(2)->appendRow(new QStandardItem("subrow31")); ui.cameraTreeView->setModel(model);
Now, when I expand (some of) the top-level rows and change the selected entry, on the console output like the following is generated (several lines per selection change):
qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 6 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 6 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 6 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 6 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 6 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5 qt.accessibility.core: Cannot create accessible child interface for object: QTreeView(0x1c7b87e5a90, name = "cameraTreeView") index: 5
Does someone have an idea what the problem here could be?
I am working on Windows 10, I have seen the behavior using Qt 5.10.0 and 5.12.2 (debug binaries). Thanks. -
Hi
It really sounds like this one
https://bugreports.qt.io/browse/QTBUG-33247
but should be fixed many versions ago.So that code + ui form with QTreeView is enough to trigger the message ?
-
I made a minimal example of this and know now how to replicate the behavior. The example is as follows:
QTreeViewTest.ui:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>QTreeViewTestClass</class> <widget class="QMainWindow" name="QTreeViewTestClass"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>885</width> <height>645</height> </rect> </property> <property name="windowTitle"> <string>QTreeViewTest</string> </property> <widget class="QWidget" name="centralWidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBox"> <property name="enabled"> <bool>false</bool> </property> <property name="title"> <string>GroupBox</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTreeView" name="treeView"> <attribute name="headerVisible"> <bool>false</bool> </attribute> </widget> </item> </layout> </widget> </item> </layout> </widget> </widget> <layoutdefault spacing="6" margin="11"/> <resources> <include location="QTreeViewTest.qrc"/> </resources> <connections/> </ui>
QTreeViewTest.h:
#pragma once #include <QtWidgets/QMainWindow> #include "ui_QTreeViewTest.h" class QTreeViewTest : public QMainWindow { Q_OBJECT public: QTreeViewTest(QWidget *parent = Q_NULLPTR); protected slots: void fillTreeView(); private: Ui::QTreeViewTestClass ui; };
QTreeViewTest.cpp:
#include "QTreeViewTest.h" #include <QStandardItemModel> #include <QTimer> QTreeViewTest::QTreeViewTest(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); //ui.groupBox->setEnabled(false); QTimer::singleShot(1000, this, &QTreeViewTest::fillTreeView); } void QTreeViewTest::fillTreeView() { //ui.groupBox->setEnabled(false); QStandardItemModel *model = new QStandardItemModel(); QStandardItem *parentItem = model->invisibleRootItem(); parentItem->appendRow(new QStandardItem("row1")); parentItem->appendRow(new QStandardItem("row2")); parentItem->appendRow(new QStandardItem("row3")); parentItem->child(0)->appendRow(new QStandardItem("subrow11")); parentItem->child(1)->appendRow(new QStandardItem("subrow21")); parentItem->child(2)->appendRow(new QStandardItem("subrow31")); ui.treeView->setModel(model); ui.groupBox->setEnabled(true); }
The QTreeView is embedded in a QGroupBox. The appearance of the effect depends on the enabled state (i.e. void setEnabled(bool)) of the QGroupBox.
The following cases list scenarios about appearance of the debug output in dependence of the enabled state of the QGroupBox:
QGroupBox disabled in Designer: YES
QGroupBox disabled in constructor of QTreeViewTest: NO
QGroupBox disabled as first statement in fillTreeView(): NOFor completeness, the following cases list scenarios about appearance of the debug output in dependence of the enabled state of the QTreeView itself:
QTreeView disabled in Designer and enabled at the end of fillTreeView(): NO
QTreeView disabled in constructor of QTreeViewTest and enabled as last statement in fillTreeView(): NO
QTreeView disabled as first statement in fillTreeView() and enabled as last statement in fillTreeView(): NOThe conclusion of my investigation therefore is that the effect only appears when the QTreeView resides in a QGroupBox that comes disabled from the designer. The effect also does not change if I enable the QGroupBox before I set the QStandardItemModel to the QTreeView.
I now work around this issue by disabling my QGroupBox in the constructor of the parent object instead of disabling it the designer file. However, maybe someone can investigate further to identify the root-cause of this.