How to anchor QGraphicsWidget/Item (make them static) on QGraphicsView

扶醉桌前 提交于 2020-02-25 04:36:20

问题


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.


回答1:


You should just have to create your widgets and specify the QGraphicsView in the constructor like this:

QPushButton *button1 = new QPushButton(view);


来源:https://stackoverflow.com/questions/3683565/how-to-anchor-qgraphicswidget-item-make-them-static-on-qgraphicsview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!