PDA

View Full Version : QGraphicsView won't update until resize



stevel
27th February 2009, 19:39
In my project, I have a QGraphics view that I can add various kinds of QGraphicsItems to. I recently refactored some code, and after this change, the QGraphicsView no longer refreshes when I add a new item, when I move an item, or resize an item.

When I click on an item, and move the mouse, nothing changes on the screen until I resize the window, at which time, the view is redraw with the item in the new location.

I'm running QT 4.4.3 on a Mac running OS X 10.4.

I've searched the forum, and seen that several other people have posted very similar questions, but no one posted the answer to how they solved the problem.

When I resize the window containing the scene, everything redraws, and the moving/resizing I have done shows up.

I do have some code associated with the mouse events, but this code seems to be working as far as I can tell.

I think I could fix this by adding lots of update calls through out the code, but I don't think I should need to do this.

Here's the code where the view is initialized:



worksheetScene = new QGraphicsScene();
itsDrawList = new EWorksheetView(this);

// JSL - single sceneDrawCommon for common drawObject behavior
sceneDrawCommon = new EDrawCommon();
worksheetScene->addItem(sceneDrawCommon);

itsDrawList->setScene(worksheetScene);
setWidget(itsDrawList);


Here's the creator for the view:
(EDrawListView is an ancestor for EWorksheetView



//
// JSL - EDrawListView
//
EDrawListView::EDrawListView(EDrawListWindow *aWindow)
{
itsWindow = aWindow;

wkDefaultColor = QColor(100, 100, 100, 255).rgba();
wkAntiAliasing = true;

setViewportUpdateMode(QGraphicsView::SmartViewport Update);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn );
setDragMode(QGraphicsView::RubberBandDrag);
setAcceptDrops(true);

show();
}



If anyone has any suggestions, I would appreciate hearing them. Also, if anyone wants to see the Event code, let me know.

Thanks

stevel
27th February 2009, 21:45
I believe that I have resolved this. I am going to post what I found here, in the hopes that it will help someone else with the same problem. I am also going to sent a bug report to trollTech/Nokia, because I think that this is basically a bug in QT.

If you call show on the view before the view is connect to a scene, the view gets into a state where it has refresh problems from then on. Perhaps there is a way to make it recover from this state, but I don't see it. If you call show only after there is a scene associated with the view, everything is fine.