Problem getting view to update when scene changed
-
I have a qGraphicsScene with a bunch of QGraphicsObjects on it. I also have a QGraphicsView. For the most part, everything works. The problem I am having is that when a user drags the QGraphicsObject off of the view, the view doesn't update and the scrollbars don't change. The item is there, but it isn't visible because the screen cannot be scrolled to the item.
I have a method that is called when the item is moved. The method gets called as expected. The current code that I have is as follows:
const QRectF boundingRect = myScene->itemsBoundingRect(); myScene->setSceneRect(boundingRect); myScene->update(boundingRect); myView->viewport()->update(); myView->setScene(myScene); myView->updateSceneRect(myScene->sceneRect());I have tried all sorts of combinations of the above, most of which I got from AI as nothing else seemed to work. None of this did any good.
I have verified that the scene does indeed expand when I drag something off the left side of the view. The minimum value for the horizontal scroll bar is 0 before the above code executes, and is still 0 after the code executes. I believe that the scene isn't getting updated.
I did try calling QApplication::processEvents() as suggested by AI, but that didn't help. Getting the graphicsView rectangle, mapping it to the screen, and checking if the QGraphicsObject's rectangle intersects the view rectangle returns true. Maybe the scene is updated, but the scrollbar doesn't change to reflect it.
Anyone have any suggestions?
Thanksmore code of interest
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); setAlignment(Qt::AlignLeft | Qt::AlignTop); setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); -
Hi,
Which version of Qt are you using ?
On which OS ?
Can you provide a minimal compilable example that shows this behaviour ? -
Hi,
Which version of Qt are you using ?
On which OS ?
Can you provide a minimal compilable example that shows this behaviour ?