简体   繁体   English

QTabWidget 与 QGraphicsView

[英]QTabWidget with QGraphicsView

I have a QTabWidget and second page containing a QGraphicsView with scene.我有一个QTabWidget和第二页,其中包含一个带有场景的QGraphicsView The scene canvas is larger than the QGraphicsView's viewport and I'm using QScrollBar to move objects on the scene.场景画布比 QGraphicsView 的视口大,我使用QScrollBar移动场景上的对象。

On the scene I place a lot of QGraphicsItem objects.在场景中,我放置了很多 QGraphicsItem 对象。 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 .QGraphicsview坐标在左上角开始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.移动场景中的对象后,如果我将QTabWidget的页面从第二页更改为第一页然后再返回,则坐标的起点将移动到QGraphicsView的中心,并且场景中的所有对象都会自动移动到新位置。

This happens only when I'm using a QTabWidget , if I change the parent of QGraphicsView to QWidget, all works well.这仅在我使用QTabWidget时发生,如果我将 QGraphicsView 的父级更改为 QWidget ,则一切正常。

I found a solution.我找到了解决方案。 Just need to calculate rect of the scene, and set obviously using QGraphicsScene::setSceneRect() method.只需要计算场景的矩形,并使用 QGraphicsScene::setSceneRect() 方法进行设置。 Otherwise, position of my scene in the QGraphicsView may surprise.否则,我的场景在 QGraphicsView 中的位置可能会令人惊讶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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