简体   繁体   中英

I can change all the qt wingets background except window

I'm facing a problem, I cant change the backgroun from a qt window. I can change the background of my MainWindow and all the other widgets but when I try to do that in another window it dont change. I'm using the same image for all the widgets and windows so the location is not the problem.

I'm using qt designer with stylesheet and visual Studio 2013. One thing that is weird is that in the QtDesigner the MainWindow background is not visible until I compile and run everything but in the other windows the background is visible but when I compile is gonne.

I already try by code but the same result.

Any help?

Looking in another similar questions I found this: QtStylesheet

The answer to my problem is the second answer from that post. The problem was that I have to reimplement the paintEvent() because without that the widget will support only the background, background-clip and background-origin properties.

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

The code was taken from the answer in the other post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM