QGraphicsView/QGraphicsScene渲染问题

发布于 2024-09-08 04:29:43 字数 603 浏览 3 评论 0原文

我在我的应用程序中使用 QGraphicsScene/QGraphicsView 对。 为了我的目的,我对它们进行了子类化。生成该对的代码片段如下:

itsScene = new QGraphicsScene;
itsView = new QGraphicsView;
itsView->setParent(itsCanvas);

itsView->setGeometry(20,20,1700,720);
itsView->setBackgroundBrush(Qt::black);
itsView->setAlignment(Qt::AlignTop);
itsView->setScene(itsScene);

将一些小部件添加到 QGraphicsScene 中后,我的应用程序最终 UI 快照如下: 应用程序 UI快照我的问题是为什么图片上方有一些可用空间?可能是什么原因造成的? 我正在为我的小部件使用一些负坐标。跟那个有关系吗?

I am using QGraphicsScene/QGraphicsView pair in my application.
I had subclassed them for my purpose. The code snippet that generate the pair is below:

itsScene = new QGraphicsScene;
itsView = new QGraphicsView;
itsView->setParent(itsCanvas);

itsView->setGeometry(20,20,1700,720);
itsView->setBackgroundBrush(Qt::black);
itsView->setAlignment(Qt::AlignTop);
itsView->setScene(itsScene);

After adding some widgets into QGraphicsScene my application final UI snapshot is below:
Application UI snapshot

Here my question is why there is some free space above the picture? What may cause this?
I am using some negative coordinates for my widgets. Is it related with that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2024-09-15 04:29:43

负坐标可能是原因。 QGraphicsScene 通过组合其中所有项目的边界来计算其边界矩形。

如果您知道场景边界,请调用 setSceneRect 将其修复为已知的矩形。这样,放置在边界之外的图形项目将不会导致场景扩展超出您想要的范围。

The negative coordinates may be the cause. QGraphicsScene calculates its bounding rect from combining the bounds of all items in it.

If you know your scene bounds, call setSceneRect to fix it down to a known rect. This way graphics items placed out of the bound will not cause the scene to expand beyond what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文