#include class Widget : public QWidget { Q_OBJECT public slots: void print(QPrinter *); public: Widget(QWidget *parent = 0); private: QPrintPreviewDialog *dialog; QPrinter *printer; QToolButton *button; }; Widget::Widget(QWidget *parent) : QWidget(parent) { button = new QToolButton(this); button->setText("Rendering of this tool button causes the print preview widget to resize."); printer = new QPrinter(QPrinter::ScreenResolution); // when the parent is not set to the widget, it doesn't get resized either dialog = new QPrintPreviewDialog(printer, this); connect(dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*))); connect(button, SIGNAL(pressed()), dialog, SLOT(exec())); } void Widget::print(QPrinter *printer) { QPixmap pixmap; // uncomment the following line to see the resizing button->render(&pixmap); QPainter p(printer); p.drawEllipse(0, 0, 400, 600); p.end(); } int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget widget; widget.show(); return a.exec(); } #include "main.moc"