How to render a red push button using QStyle.drawControl()?

Viewed 11629

With the following code I tried to render a red push button using QStyle.drawControl():

#include <QtCore/QtCore>
#include <QtGui/QtGui>

class Widget : public QWidget
{
    virtual void paintEvent(QPaintEvent* event)
    {
        QStyleOptionButton opt;
        opt.palette = QPalette(Qt::red);
        opt.state = QStyle::State_Active | QStyle::State_Enabled;
        opt.rect = QRect(50, 25, 100, 50);
        QPainter painter(this);
        style()->drawControl(QStyle::CE_PushButton, &opt, &painter);
    }
};

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    Widget w;
    w.resize(200, 100);
    w.show();
    return app.exec();
}

However I get the following result:

enter image description here

How do I render a red push button using QStyle.drawControl()?

I'm using Qt 4.8.1 and Visal Studio 2010 on Windows XP.

2 Answers
Related