Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.9
-
None
-
x64
Description
Hi,
Widgets added to a QTreeWidget embedded into a QGraphicsScene does not scroll along with the scrollbar.
In the example below, a label is set as an itemWidget of column 2.
Initialy, the label is at the right position, but when you scroll to the right, it stays in place.
Resizing ANY column replace the label to its correct position.
This bug also happen with vertical scrolling.
Code for reproduction :
int main(int argc, char *argv[]) { QApplication a(argc,argv); auto aView = new QGraphicsView(); auto aScene = new QGraphicsScene(); aView->setScene( aScene ); auto aTW = new QTreeWidget(); aTW->setColumnCount(7); QTreeWidgetItem* aTRI = new QTreeWidgetItem(aTW,{"zero","one", "two", "three", "four","five","six"}); // to have a scroll bar QLabel* aLabel = new QLabel("Label", aTW); aTW->setItemWidget(aTRI, 1, aLabel ); //// uncomment to have the bug vertically too //for (int i = 2; i< 20; i++) { // aTW->setItemWidget(new QTreeWidgetItem(aTW,{"zero"+QString::number(i),"one", "two", "three", "four","five","six"}), 1, new QLabel("Label"+QString::number(i), aTW) ); //} auto _proxy = new QGraphicsProxyWidget(); _proxy->setWidget(aTW); aScene->addItem( _proxy ); aView->show(); return a.exec(); }
I tried a lot (update, repaint the label, ...) and i only found this ugly workaround :
QObject::connect(aTW->horizontalScrollBar(), &QScrollBar::valueChanged, aTW,[&]{ aTW->setColumnWidth( 1 , aTW->columnWidth(1)+1); aTW->setColumnWidth( 1 , aTW->columnWidth(1)-1); });
I am looking for a better workaround / fix.
Thanks.