nico
nico

Reputation: 110

Can't override VideoWidget paintEvent() in QT C++

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!

Upvotes: 1

Views: 1339

Answers (1)

Kamil Klimek
Kamil Klimek

Reputation: 13130

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:

void myVideoWidget::paintEvent(QPaintEvent *event){
    Phonon::VideoWidget::paintEvent(event); // perform paint event from inherited class
    QPainter painter(this);
    painter.setPen(QPen(Qt::red,3));
    qDebug()<< "repintando";
    painter.drawEllipse(500,500,100,100);
}

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.

Upvotes: 1

Related Questions