Qt World Summit: Register Today!

QPainter::begin: Paint device returned engine == 0, type: 2

  • This is a long shot given the nature of my problem, but can anyone here help me debug this message I'm seeing in my debug output?
    QPainter::begin: Paint device returned engine == 0, type: 2

    It occurs when I add about 10 columns with checkboxes to a QTreeView and QTreeWidget, and I hover over the columns or resize them.

    I tried first with a QTreeWidget and creating everything manually (like calling setItemWidget(..) with a QCheckBox as an argument.
    I then tried it with a QStandardItemModel by adding QStandardItems with setCheckable set to true.

    I get the exact same behaviour: a few messages like that every now and then.
    The actual functionality of the form and control don't seem to be affected; Should I just ignore it?
    I am running under Windows 7/64 bit with QtCreator 2.1 (my app is not 64 bit).

    Thank you,
    Harry Sfougaris

  • Have you tried debugging into Qt to see what causes this message (you'll need a debug build of Qt)? Can you provide a small compilable example that reproduces this please?

  • I agree with ZapB. You have to provide a compilable example or a backtrace for this issue. without seeing the code, it's impossible to tell what the problem is.

  • Ok, here it is.

    Since I can't attach the project:
    It's a simple project, the one creator generates.
    I added in designer a treeview to the MainWindow and laid it out vertically.

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QStandardItemModel>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    Ui::MainWindow *ui;
    void prepareDataSrc();
    QStandardItemModel *dataSrc;

    #endif // MAINWINDOW_H

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QStandardItem>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    dataSrc = new QStandardItemModel();
    ui->tVw->setColumnWidth(0, 250);

    void MainWindow::prepareDataSrc(){
    QStringList hdr;
    hdr << "Descr" << "Col0" << "Col1" << "Col2" << "Col3" << "Col4" << "Col5" << "Col6" << "Col7" << "Col8" << "Col9";

    for (int i = 0; i < 100; i++) {
        QList<QStandardItem*> iRow;
        QStandardItem *iDescr = new QStandardItem();
        iDescr->setText( QString("Item #%1").arg(i));
        iDescr->setData(i, Qt::UserRole);
        iRow << iDescr;
        for (int i2 = 0; i2 < 10; i2++) {
            QStandardItem *_i = new QStandardItem();
            _i->setData(i2, Qt::UserRole);
             iRow << _i;
        if (iDescr->hasChildren()) {
            QFont f = iDescr->font();


    delete ui;

    #include <QtGui/QApplication>
    #include "mainwindow.h"
    #include <QTextCodec>

    int main(int argc, char *argv[])
    QString c = "UTF-8";

    QApplication a(argc, argv);
    MainWindow w;
    return a.exec&#40;&#41;;


    This reproduces it for me.
    Thank you,

  • I have tried it here (Gentoo Linux, Qt 4.7.2, raster paint engine) and I get no warnings at all from your example.

    What version of Qt are you using? Did you build it yourself or is it a pre-compiled binary distribution of Qt? What paint engine are you using?

  • I am running under Windows 7/64 bit with QtCreator 2.1.
    I am using the pre-compiled binary distribution from Qt.

    Paint engine? I don't know what you mean... I haven't done anything to explicitly use a particular engine.

  • OK so you are likely using the raster paint engine then as that is the default on Windows.

    Which version of Qt though? 4.7.0, 4.7.1, 4.7.2? Something older?

  • I'm sorry I missed to specify it... 4.7.2

  • Hi,

    on windows using MSVS 2008 and pre build binaries, on Win7 32 bit, I can't reproduce this behavior.
    But if you look at the Qt code it is printed out, when

    bool QPainter::begin(QPaintDevice *pd)

    d->engine = pd->paintEngine();
    if (!d->engine) {
        qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType());
        return false;


    It could perhaps be a 64 bit issue.

  • But my app isn't a 64 bit app...
    Thankfully whatever it misses to paint is not visible, but it's still strange...

  • But you are using 64 but win 7.
    Ups sorry, my system is win XP, not win 7

  • So I guess this needs to be verified by someone running Win7/64 bit, to see if it can be reproduced...

  • can anyone running Win7/64 bit, please run the above code to see if it can be reproduce?

  • Just tried this with W7/64 on Qt 4.8.3 MinGW distribution, no messages or warnings running this code. Also tried 4.7.4 MinGW distribution, no warnings there. It shows the items properly, the checkboxes and list also behave properly.

Log in to reply