简体   繁体   中英

QTabWidget with QGraphicsView

I have a QTabWidget and second page containing a QGraphicsView with scene. The scene canvas is larger than the QGraphicsView's viewport and I'm using QScrollBar to move objects on the scene.

On the scene I place a lot of QGraphicsItem objects. I have a horizontal and a vertical scroll bar, and some items can move only horizontally, another objects on scene can move only vertically.

My QGraphicsview coordinates start at the top left corner of QGraphicsview . After moving objects on the scene, if I change the page of the QTabWidget from second page to first and then back again, the start of coordinates is moved to the center of QGraphicsView, and all objects on the scene are moved to new positions automatically.

This happens only when I'm using a QTabWidget , if I change the parent of QGraphicsView to QWidget, all works well.

I found a solution. Just need to calculate rect of the scene, and set obviously using QGraphicsScene::setSceneRect() method. Otherwise, position of my scene in the QGraphicsView may surprise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM