Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.15.2, 6.2.0 Alpha
-
-
f6bca6261156e8f648bf7d41ba1728ef17cd6889 (qt/qtbase/dev) ba0bca338c4fa743b007a4c4f204f09f9e5a8a80 (qt/tqtc-qtbase/5.15) 8df72123254277454f46945171194d1aa945b1d2 (qt/qtbase/6.1) 96222ec18c0e14995ae843cde9faf8a1b96d4943 (qt/qtbase/6.2)
Description
Issue
When the model is asynchronous (like QFileSystemModel, or the example model at https://code.qt.io/cgit/qt/qtopcua.git/tree/examples/opcua/opcuaviewer ), expandToDepth() might stop expanding before the desired depth is reached.
The same occurs with expandAll().
Demo
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication a(argc, argv); auto model = new QFileSystemModel; model->setRootPath("C:/tmp"); QTreeView tree; tree.setModel(model); QPushButton button("Click me to expand"); QObject::connect(&button, &QPushButton::clicked, [&]{ tree.expandToDepth(3); }); tree.show(); button.show(); return a.exec(); }
- Expected behaviour: 1 click should expand the tree to depth 3
- Actual behaviour: Multiple clicks are required to reach depth 3 (Although depending on your filesystem size, the last click will likely freeze the app)
Workaround
Call `expandToDepth(depth)` repeatedly (with a slight wait between each call) until the desired depth is reached. Each call causes the model to fetch a bit more data, so it allows expansion to proceed a bit further.
Attachments
For Gerrit Dashboard: QTBUG-94981 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
359857,3 | Point out that QTreeView's expandAll/expandToDepth don't fetch data | dev | qt/qtbase | Status: MERGED | +2 | 0 |
359935,2 | Point out that QTreeView's expandAll/expandToDepth don't fetch data | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |
359936,2 | Point out that QTreeView's expandAll/expandToDepth don't fetch data | 6.1 | qt/qtbase | Status: MERGED | +2 | 0 |
359943,2 | Point out that QTreeView's expandAll/expandToDepth don't fetch data | tqtc/lts-5.15 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |