简体   繁体   English

我可以更改除窗口以外的所有Qt wingets背景

[英]I can change all the qt wingets background except window

I'm facing a problem, I cant change the backgroun from a qt window. 我遇到问题,无法从qt窗口更改背景。 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. 我可以更改MainWindow和所有其他小部件的背景,但是当我尝试在另一个窗口中进行更改时,它不会改变。 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. 我正在使用带有样式表和Visual Studio 2013的qt Designer。奇怪的是,在QtDesigner中,MainWindow背景在我编译并运行所有内容之前是不可见的,但是在其他窗口中背景是可见的,但是当我编译时。

I already try by code but the same result. 我已经尝试通过代码,但结果相同。

Any help? 有什么帮助吗?

Looking in another similar questions I found this: QtStylesheet 在寻找另一个类似的问题时,我发现了这一点: 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. 问题是我必须重新实现paintEvent(),因为没有它,该小部件将仅支持background,background-clip和background-origin属性。

 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. 该代码取自另一篇文章的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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