在绘制后绘制自定义窗口小部件 [英] Draw on custom widget after it's drawing

查看:127
本文介绍了在绘制后绘制自定义窗口小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的widget,它继承了QWidget。它有自己的paintEvent,我不能改变它。所以我想在我的对话框对象中使用这样一个小部件,但我需要绘制一些图形,它在绘制自己的图形(该小部件在其上绘制视频帧,我需要绘制一些线条)。我可以绘制每个时间后的paintEvent的小部件吗?我使用installEventFilter并捕获事件wuth类型Qt :: Paint,但我canoont看到我淹没的任何东西。是否有其他方法?

解决方案


  1. 重新实现 paintEvent ,并先调用继承的 paintEvent ,然后执行绘制。


  2. 您可以在窗口小部件上安装事件过滤器,并执行相同的操作:首先调用窗口小部件的 paintEvent ,然后执行绘图。


  3. 隐藏其他小部件。创建自己的窗口小部件,并在窗口小部件的 paintEvent 中调用其他窗口小部件的 render 由于另一个窗口小部件可能会渲染随时间变化的视频帧,因此您可能需要使用 update()的定时器。


在这两种情况下,您都不会修改第三方自定义窗口小部件。



其他窗口小部件的保护 paintEvent 你需要使用 QWidget ,即使只是一个虚拟的,不可见的。 >

I have a custom widget, which inherits QWidget. It has own paintEvent and I cannot change it. So I want to use such a widget in my dialog object, but I need to draw some graphics on it after it draws its own graphics (that widget draws video frames on it, an I need to draw some lines over it). Can I draw every time after the paintEvent of that widget? I used installEventFilter and caught the event wuth type Qt::Paint, but I canoont see anything I've drown. Is there any other way?

解决方案

  1. You can derive from the custom widget class, reimplement paintEvent, and call the inherited paintEvent first, then do your drawing.

  2. You can install an event filter on the widget and do the same: call the widget's paintEvent first, then do your drawing.

  3. Hide the other widget. Create your own widget, and call the other widget's render method in your widget's paintEvent, then do your drawing. Since the other widget is presumably rendering video frames that change periodically over time, you might need to use a timer to update() your widget.

In neither case are you modifying the 3rd party custom widget.

In order to call other widget's protected paintEvent you need to be using a QWidget, even if just a dummy, invisible one.

这篇关于在绘制后绘制自定义窗口小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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