在paintEvent之外的Qt Painter - 不可能 - 解决方法? [英] Qt Painter outside paintEvent - impossible - workaround?

查看:40
本文介绍了在paintEvent之外的Qt Painter - 不可能 - 解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,Qt4 似乎不允许您在绘制事件之外的窗口上进行绘制.我有很多代码希望能够绘制橡皮筋线(然后我在给定的 UI 中实现的特定专有接口的通用绘图代码).我已经阅读了有关 pixmap 方法的内容,这需要大量工作,而且我认为这不是我真正想要的.

So it appears that Qt4 doesn't let you draw on windows outside of a paint event. I have a lot of code that expects to be able to in order to draw rubber band lines (generic drawing code for a particular, proprietary interface that I then implement in the given UI). I've read about the pixmap method, it would be a lot of work and I don't think it's really what I want.

是否有一种解决方法可以让我做我想做的事?我只需要在屏幕上绘制 XOR 带.

Is there a workaround that allows me to do what I want anyway? I just need to draw XOR bands on the screen.

尝试了 WA_PaintOutsidePaintEvent 标志.然后我看到说它在 Windows 上不起作用.

Tried the WA_PaintOutsidePaintEvent flag. Then I saw the bit that says it doesn't work on Windows.

推荐答案

在现代合成桌面中,窗口绘制需要由窗口管理器同步,以便 alpha 混合和其他效果可以依次应用到正确的背面缓冲区 - 然后将其结果翻转到屏幕上以允许无撕裂的窗口动画.

In modern compositing desktops window painting needs to be synchronized by the window manager so that the alpha blending and other effects can be applied, in order, to the correct back buffers - the result of which is then flipped onto the screen to allow tear-free window animations.

在此过程的带外调用绘制操作 - 虽然由于底层平台上的遗留原因支持 - 会破坏此过程并导致执行许多非常非最佳的代码路径.

Invoking painting operations out-of-band of this process - while supported for legacy reasons on the underlying platforms - would subvert this process and cause a number of very non optimal code paths to be executed.

基本上,当您要在窗口上绘画时:调用 invalidate 函数以尽快安排绘画,并在绘画事件期间绘画.

Basically, when you have painting to do on a window: Call the invalidate function to schedule the painting soon, and paint during the paint event.

这篇关于在paintEvent之外的Qt Painter - 不可能 - 解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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