强制QGraphicsItem要留 [英] Forcing QGraphicsItem To Stay Put

查看:114
本文介绍了强制QGraphicsItem要留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 QGraphicsScene 充满 QGraphicsItems ,用户可以平移和缩放检查所有的 QGraphicsItems 。但是,我想有一个 QGraphicsTextItem 标签,总是保持在屏幕的左上角。忽略缩放很容易,因为我可以只是 setFlags(QGraphicsItem :: ItemIgnoresTransformations),但我还没有想出如何强制位置保持在顶部 - 剩下。

I have a QGraphicsScene that is filled with QGraphicsItems, and the user is able to pan and zoom around to inspect all of the various QGraphicsItems. However, I would like to have a QGraphicsTextItem label that always stays put at the top left of the screen. Ignoring the zooms is easy, as I can just setFlags(QGraphicsItem::ItemIgnoresTransformations), but I've yet to figure out how to force the position to stay at the top-left. What's the best way to make my label "float" in the same place?

推荐答案

也许你只想放一个普通的 QLabel 直接在视图上,而不是试图使一部分场景留在一个地方,如此问题

Perhaps you just want to put a regular QLabel right on the view instead of trying to make a part of the scene stay in one place as discussed in this question.

注意: / strong>正如在另一个答案中提到的,这个技巧通常不会与硬件加速视图一起使用。在这些情况下,您需要将文本项目作为场景的一部分。

Note: As mentioned in another answer, this trick will often not work with hardware accelerated views. In these cases, you will need to make the text items a part of the scene.

这篇关于强制QGraphicsItem要留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆