Qt重绘持久性
我正在 Qt (C++) 中创建一个简单的 Paint 程序,您可以在其中选择一个形状,它会跟随您的鼠标在画布上移动,直到您单击,此时该形状会锁定到屏幕上的该位置。然后,用户可以继续以这种方式,向屏幕添加越来越多的形状。我的问题在于点击后让这些形状保持在原位。我尝试使用 this->setAttribute(Qt::WA_OpaquePaintEvent, true),但是一旦我再次将该属性设置为 false,我就会丢失数据。有什么方法可以“锁定”屏幕,以便我的旧内容保留在屏幕上,而新内容被覆盖?
I'm creating a simple Paint program in Qt (C++) where you pick a shape and it follows your mouse around on a canvas until you click, at which point that shape locks to the screen at that position. The user can then continue in this manner, adding more and more shapes to the screen. My problem lies in getting these shapes to stay in place after I click. I tried using this->setAttribute(Qt::WA_OpaquePaintEvent, true), but as soon as I set that attribute false again I lose my data. Is there some way I can "lock" the screen so my old stuff stays on it while the new stuff gets overwritten?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想保留绘制的数据,你应该先绘制到 QPixmap,然后在你的小部件上绘制这个 QPixmap。
If you want to keep the painted data, you should draw to a QPixmap first then paint this QPixmap on your widget.