如何在 QGraphicsView 上锚定 QGraphicsWidget/Item(使它们静态) [英] How to anchor QGraphicsWidget/Item (make them static) on QGraphicsView
问题描述
我想做一个类似 hud 的东西.我有一个带有巨大 QPixmap
的 QGraphicsScene
,我将它添加到一个小得多的 QGraphicsView
.现在我需要添加一些控制元素,例如 QLabel
、QPushButton
和 QGraphicsEllipseItem
.那,我认为,不是问题.我发现这个有用的页面 Graphics View Classes.但是我如何将这个控制元素锚定到 View 或者更好地说我如何不锚定它们?当我拖动 QPixmap
时,我不希望 hud 与 QPixmap
一起移动到 QGraphicsView
之外.我需要做什么,才能解决这个问题.希望可以有人帮帮我.
I want to make something like a hud. I have a QGraphicsScene
with a huge QPixmap
, that I added to a much smaller QGraphicsView
. Now I need to add some control elements, like QLabel
, QPushButton
and QGraphicsEllipseItem
. That's, I think, is not a problem. I found this helpful page Graphics View Classes. But how do I anchor this control elements to the View or maybe better said how do I not anchor them? When I drag the QPixmap
, then I don't want that the hud is moving with the QPixmap
out of the QGraphicsView
.
What do I need to do, to solve this problem. Hope someone can help me.
推荐答案
您应该只需要创建小部件并在构造函数中指定 QGraphicsView
,如下所示:
You should just have to create your widgets and specify the QGraphicsView
in the constructor like this:
QPushButton *button1 = new QPushButton(view);
这篇关于如何在 QGraphicsView 上锚定 QGraphicsWidget/Item(使它们静态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!