无法覆盖 QT C 中的 VideoWidget PaintEvent()
我试图在 Phonon 库中的 VideoWidget 上绘制一些形状,但我无法重写 PaintEvent() 方法。
如果我尝试实现这样的方法:
void Phonon::VideoWidget::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(QPen(Qt::red,3));
qDebug()<< "repintando";
painter.drawEllipse(500,500,100,100);
}
我收到此错误:没有在类 'Phonon::VideoWidget' 中声明的 'void Phonon::VideoWidget::paintEvent(QPaintEvent*)' 成员函数
所以我决定创建一个 myVideoWidget 标头受保护的方法 PaintEvent 并在 mainwindow.cpp 中实现它,如下所示:
void myVideoWidget::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(QPen(Qt::red,3));
qDebug()<< "repintando";
painter.drawEllipse(500,500,100,100);
}
程序运行,但不绘制任何内容或显示“repintando”消息。
谁能帮助我吗?我做错了什么?
非常感谢!
I'm trying to draw some shapes over a VideoWidget from the Phonon library, but I can't override the paintEvent() method.
If I try to implement the method like this:
void Phonon::VideoWidget::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(QPen(Qt::red,3));
qDebug()<< "repintando";
painter.drawEllipse(500,500,100,100);
}
I get this error: no ‘void Phonon::VideoWidget::paintEvent(QPaintEvent*)’ member function declared in class ‘Phonon::VideoWidget’
So I decided to create a myVideoWidget header with the protected method paintEvent and implemented it in mainwindow.cpp like this:
void myVideoWidget::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(QPen(Qt::red,3));
qDebug()<< "repintando";
painter.drawEllipse(500,500,100,100);
}
And the program runs but it doesn't draw anything or displays the "repintando" message.
Can anyone help me? What am I doing wrong?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您已经交付了自己的类,该类继承了 Phonon::VideoWidget 并将其设置为播放器的视频小部件?如果是,那么您需要将您的paintEvent修改为如下所示:
但是!我不确定VideoWidget是否使用paintEvent来渲染视频帧。您可能必须手动调用您的paintEvent。尝试使用重绘而不是更新。
As I understood, You've delivered your own class, that inherits Phonon::VideoWidget and you set it as your video widget for your player? If yes, than you need to modify your paintEvent to something like this:
BUT! I'm not sure if VideoWidget uses paintEvent to render video frames. It is possible That you will have to invoke your paintEvent manualy. Try using repaint instead of update maybe.