c++ - QGraphicsView/QGraphicsScene渲染问题

标签 c++ qt qt4 rendering qgraphicsview

我在我的应用程序中使用 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 快照如下: Application UI snapshot 在这里我的问题是为什么图片上方有一些空闲空间?这可能是什么原因造成的? 我为我的小部件使用了一些负坐标。跟那个有关系吗?

最佳答案

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

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

关于c++ - QGraphicsView/QGraphicsScene渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3157786/

相关文章:

c++ - 不使用第三方头文件编写纯代码

c++ - 如何在另一个项目的dll中添加调用函数

c++ - Qt,C++ : QGraphicsScene coordinates are not working

python - PyQt5 - 正确动态调整组件大小和布局组件

Javascript/ Jasmine : ReferenceError: Can't find variable: Float64Array

c++ - 回车在 xcode 控制台 c++ 中不起作用

c++ - 如何在 C++ 中向 std::priority_queue 添加键/优先级?

c++ - 如何将一个QMap放入另一个QMap

multithreading - 使用 QThreadPool 时如何执行 QObject::moveToThread()?

Qt - 如何访问 QTreeWidget 中插入的 QComboBox 数据