在Qt4中,如何检查paintEvent是否由调整大小触发?

发布于 2024-08-07 07:52:55 字数 277 浏览 4 评论 0原文

在 Qt4 应用程序中,是否可以在 paintEvent() 处理程序内部判断重绘是否是由调整大小触发的?

我有一个重绘速度非常慢的小部件(一个复杂的绘图),我想通过在小部件调整大小时仅通过位块传输调整大小的像素图来加速调整大小,并且仅在调整大小时重绘小部件调整大小完成。

我尝试在 resizeEvent() 的开头和结尾设置/取消设置标志,但这似乎不起作用(即该标志在 paintEvent() 中始终处于关闭状态>)。

In a Qt4 application, is it possible to tell inside a paintEvent() handler whether the repaint was triggered by a resize or not?

I have a widget which is very slow to redraw (a complicated plot), and I want to speed up resizes by just blitting a resized pixmap while the widget is being resized, and only redraw the widget when the resize is complete.

I've tried setting/unsetting a flag at the beginning and end of resizeEvent() but that doesn't seem to work (i.e. the flag is always off in paintEvent()).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生百味 2024-08-14 07:52:55

我认为你不能轻易做到这一点。很难判断调整大小何时开始/停止,尤其是以跨平台方式。我可能有一个由 resizeEvent 触发的单次计时器,它将图像渲染到 QPixmap 上。如果在计时器仍处于活动状态时收到另一个 resizeEvent,只需重新启动它即可。在paintEvent中始终绘制当前的像素图,并且在从计时器渲染新的像素图后,在小部件上调用update()。这不是一个理想的解决方案,但它应该有效。

I don't think you can easily do this. It's kind of hard to tell when resizing started/stopped, especially in a cross-platform way. I'd probably have a single-shot timer triggered by resizeEvent, that would render the image onto a QPixmap. If you get another resizeEvent while the timer is still active, just restart it. In paintEvent always paint the current pixmap, and after you render a new pixmap from the timer, call update() on the widget. Not an ideal solution, but it should work.

寒冷纷飞旳雪 2024-08-14 07:52:55

您可以采取的一种方法是始终绘制像素图,但请记住,如果窗口大小发生更改,请“尽快”重新创建像素图。

因此,当paintEvent到来时,如果大小与当前像素图大小不同,则无论如何绘制存储的像素图,但然后设置(或重置)QTimer 触发一个信号到一个槽,该槽将刷新像素图。

当此刷新方法运行时,它将重新渲染像素图并请求刷新小部件。

One approach you could take is to always paint the pixmap, but remember to recreate the pixmap "soon" if the window size has changed.

So, when the paintEvent comes in, if the size is different to current pixmap size, then paint the stored pixmap anyway, but then set (or reset) a QTimer to trigger a signal to a slot which will refresh the pixmap.

When this refresh method runs, it will re-render the pixmap and request a refresh of the widget.

淡墨 2024-08-14 07:52:55

另一种可能性是看看 QMdiSubWindow::RubberBandResize是在内部实现的,它可能会提供有关如何实现此目的的提示。如果我没记错的话,仅适用于 QMdiSubwindow - 它在调整大小期间“停止”绘画(带有透明主体的小窗口边框除外),并在停止调整窗口大小时触发一个最终的 resizeEvent (触发更新/绘画)...

Another possibility would be to have a look at how QMdiSubWindow::RubberBandResize is implemented internally, it may provide hints as to how to achieve this. Works only on a QMdiSubwindow if I recall correctly - it 'stops' painting (except a small window border with a transparent body) during resizing and fires one final resizeEvent (which triggers update/paint) when you stop resizing the window...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文