开发者

Qt Stylesheet mystery [duplicate]

开发者 https://www.devze.com 2023-03-16 07:08 出处:网络
This question already has answers here:开发者_开发技巧 Qt Stylesheet for custom widget (6 answers)
This question already has answers here: 开发者_开发技巧 Qt Stylesheet for custom widget (6 answers) Closed 4 years ago.

My Desktop Qt app has a large stylesheet applied. It's applied for the QApplication derived class I am using:

this->ApplyStyleSheet(":/qss/default.qss");

It works well for all QWidget objects I define and use. (using *.ui files).

My problem begins when i promote one of my QWidgets in the *.ui file I'm using to one of my own QWidget derived classes.

When my widget was QWidget, the following worked and changed the background image:

QWidget#myWidget {
    background: transparent;
    background-image: url(:/images/bg_img.png);
    background-repeat: repeat-x;
}

When I promoted the element to my custom QWidget derived class and changed to:

QMyDerivedClass#myWidget {
    background: transparent;
    background-image: url(:/images/bg_img.png);
    background-repeat: repeat-x;
}

I no longer see my background image. Obviously I am missing something. What is it... I hope one of you knows.


My bad. Posting this so that people with similar problem can find a solution:

I did not add "paintEvent" to my custom class. (which in this case draws nothing but it enables the stylesheet adherence).

void CustomWidget::paintEvent (QPaintEvent *)
{
    QStyleOption opt;
    opt.init (this);
    QPainter p (this);
    style ()->drawPrimitive (QStyle::PE_Widget, &opt, &p, this);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号