[Qt-interest] Render hidden widget to QPixmap

Liebe Markus (RtP2/TEF72) Markus.Liebe at de.bosch.com
Tue Feb 9 11:10:46 CET 2010


Hi Girish,

Thanks for the example. It works for me as well.
But I think the problem that I face is that I want to render a QDockWidget:

The following example produces 4 pixmaps:
1.) dockWidgetWithoutShow.png:  The dockwidget being rendered without being showed before;
2.) wholeWindowWithoutShow.png:         The MainWindow being rendered without being showed before;
3.) dockWidget.png:                     The dockwidget being rendered after it was shown;
4.) wholeWindow.png:                    The Mainwindow being rendered after it was shown;

On my machine (Windows XP, Qt 4.6.1) 1 and 3 are not the same.
The Pixmap of the dockwidget that was rendered before it was shown shows only part of the contents of the dockwidget.

Here is the code:

#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    for(int i = 0; i < 2; i++){
        QMainWindow* mw = new QMainWindow();
        mw->setCentralWidget(new QPushButton("foobutton"));
        QDockWidget* dock = new QDockWidget("test",mw);
        dock->setWidget(new QTextEdit("foo bar",dock));
        mw->addDockWidget(Qt::BottomDockWidgetArea,dock);

        if(i == 1){
            mw->show();
        }

        QPixmap dockWindowPixmap(dock->size());
        dock->render(&dockWindowPixmap);

        QPixmap wholeWindowPixmap(mw->size());
        mw->render(&wholeWindowPixmap);

        if(i == 0){
            dockWindowPixmap.save(QString("dockWidgetWithoutShow.png"));
            wholeWindowPixmap.save(QString("wholeWindowWithoutShow.png"));
        }else{
            dockWindowPixmap.save(QString("dockWidget.png"));
            wholeWindowPixmap.save(QString("wholeWindow.png"));
        }
    }

    return 1;
}


Regards,

Markus




More information about the Qt-interest-old mailing list