Navid
Navid

Reputation: 261

QWidget.paintevent() vs QLabel.setPixmap()

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

Upvotes: 0

Views: 1302

Answers (1)

Kamajii
Kamajii

Reputation: 1878

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.

Upvotes: 1

Related Questions