#include "mainwindow.h"#include <QPainter>#include <QLabel>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ QLabel *pLabel = new QLabel("test test test test test test test test test test ", this); pLabel->setGeometry(0, 0, 200, 100); m_Pixmap = QPixmap(pLabel->size()); m_Pixmap.fill(Qt::transparent); pLabel->render(&m_Pixmap, QPoint(), QRegion(), IgnoreMask); setGeometry(200, 200, 500, 500);}MainWindow::~MainWindow(){}void MainWindow::paintEvent(QPaintEvent *){ QPainter painter(this); painter.setBrush(QBrush(QColor(0, 200, 0))); painter.drawRect(QRect(QPoint(), size()).adjusted(100, 0, 0, 0)); painter.drawPixmap( 50, 100, m_Pixmap.width(), m_Pixmap.height(), m_Pixmap );}