Hello
I’ve noticed a strange thing happens with QTreeView. In order to demonstrate it I created a small application. The program has one and only window that is actually a QTreeView instance. This tree contains several rows, each row has a sub-branch, and inside the sub-branch there are several sub-items (see the first image attached).
To see what I mean run the app, expand the last item of the tree and its sub-branch, click the down arrow of the vertical scrollbar to scroll it a little bit down, then click 4 times quickly on the collapse/expand button (see the red circle on the image).
click_place.png
After doing that you get assertion failed.
crash.png
Seems like QTreeView can’t find an item for the mouse position, because it moved when the branch was collapsed. I’ve attached two screenshots that show the stack state (perhaps, useful).
callstack_coordinateForItem.jpgcallstack_viewportEvent.jpg
My question – is there any solution/workaround for that or should I report a bug?
Here goes the complete application code.
#include <QtCore>
#include <QtGui>
int main(int argc, char ** argv)
{
// populate data model
for (int i = 0; i < 5; ++i)
{
QList<QStandardItem *> primaryItems;
for (int f = 0; f < 10; ++f) // add sub-items to the branch 1
{
QList<QStandardItem*> subItems;
dBranch->appendRow(subItems);
}
primaryItems.first()->appendRow(dBranch);
dataModel.appendRow(primaryItems);
} // over i
treeView.setModel(&dataModel);
treeView.
header()->setResizeMode
(QHeaderView::ResizeToContents);
treeView.resize(300, 350);
treeView.show();
return app.exec();
}
#include <QtCore>
#include <QtGui>
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QStandardItemModel dataModel;
// populate data model
for (int i = 0; i < 5; ++i)
{
QList<QStandardItem *> primaryItems;
primaryItems.append(new QStandardItem(QString("primary item %1").arg(i)));
primaryItems.append(new QStandardItem("info"));
QStandardItem *dBranch = new QStandardItem("branch 1");
for (int f = 0; f < 10; ++f) // add sub-items to the branch 1
{
QList<QStandardItem*> subItems;
subItems.append(new QStandardItem(QString("sub-item %1").arg(f)));
subItems.append(new QStandardItem("sub-item info"));
dBranch->appendRow(subItems);
}
primaryItems.first()->appendRow(dBranch);
dataModel.appendRow(primaryItems);
} // over i
QTreeView treeView;
treeView.setModel(&dataModel);
treeView.setEditTriggers(QAbstractItemView::NoEditTriggers);
treeView.header()->setResizeMode(QHeaderView::ResizeToContents);
treeView.resize(300, 350);
treeView.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks