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:
itsDrawList = new EWorksheetView(this);
// JSL - single sceneDrawCommon for common drawObject behavior
sceneDrawCommon = new EDrawCommon();
worksheetScene->addItem(sceneDrawCommon);
itsDrawList->setScene(worksheetScene);
setWidget(itsDrawList);
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);
To copy to clipboard, switch view to plain text mode
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;
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setAcceptDrops(true);
show();
}
//
// JSL - EDrawListView
//
EDrawListView::EDrawListView(EDrawListWindow *aWindow)
{
itsWindow = aWindow;
wkDefaultColor = QColor(100, 100, 100, 255).rgba();
wkAntiAliasing = true;
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setDragMode(QGraphicsView::RubberBandDrag);
setAcceptDrops(true);
show();
}
To copy to clipboard, switch view to plain text mode
If anyone has any suggestions, I would appreciate hearing them. Also, if anyone wants to see the Event code, let me know.
Thanks
Bookmarks