inheritance from QWidget - StyleSheet problem

  • Hello~

    I made custom widget that inheritance from QWidget.
    But I set stylesheet option to my widget, that NOT working.
    This is my code. Could you check this and let me know what wrong with me.

    class myWidget : public QWidget {
    public :
    explicit myWidget(QWidget *parent=0);
    myWidget::myWidget(QWidget *parent) : QWidget(parent)
    // do nothing...
    int main(int argc, char **argv)
    QApplication app(argc, argv);
    QMainWindow win;
    //QWidget *w = new QWidget(&win); // CASE 1
    myWidget *w = new myWidget(&win); // CASE 2
    return app.exec();

    When I enable "CASE 1" (w == QWidget), that draw red color,
    but enable "CASE 2" (w == myWidget), that draw nothing.

    Thank you.

  • Lifetime Qt Champion

    AS far as I know, to use a styles heet for you won widget, you must override the paint event

    void myWidget ::paintEvent(QPaintEvent *)
    QStyleOption opt;
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

    please see

  • @mrjj
    Your comment solved this problem. Thanks a lot!! :-)

Log in to reply