QWidget.paintevent() vs QLabel.setPixmap()

1.2k views Asked by At

I am trying to grab a widget and show it in another widget. Which one is less expensive?

1- using QWidget.paintevent()

void MonitoringWidget::paintEvent(QPaintEvent *event)
{
    if (m_mirrorWidget){
        QPixmap mirrorPix = m_mirrorWidget->grab();
        QPainter p(this);
//        p.drawPixmap(this->rect(),mirrorPix,mirrorPix.rect());
        p.drawPixmap(ui->mirrorFrame->geometry(),mirrorPix,mirrorPix.rect());
        update();
    }
   return;
}

2- QLabel.setPixmap()?

QLabel mirrorLabel;
QPixmap mirrorPix = m_mirrorWidget->grab();
mirrorLabel.setPixmap(mirrorPix )

Thanks

1

There are 1 answers

0
Kamajii On BEST ANSWER

I would override MonitoringWidget::paintEvent() and then use the monitored widget's QWidget::render() to render the monitored widget into the MonitoringWidget.

This should roughly be equivalent to what the widget being monitored itself will do when it receives paint events.

Also you probably need some link between the monitored widget and the monitor to respond to your monitored widget's updates. I could imagine the MonitoringWidget to install an event filter into the widget being monitored and then respond to paint events there.