How do I add a background image to the QMainWindow?

后端 未结 3 2017
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 15:05

Hi I am new to QT creator. I have tried a bunch of things to set my background image for the Q mainwindow. I added a resource folder with my image. I tried to add the by usi

3条回答
  •  甜味超标
    2020-12-03 16:01

    The CSS style background will be inherited in the child widgets and thus create weird looking windows. A possible solution is to limit the background to MainWindow or #centralWidget. If, additionally, you want to stretch the image to cover the full widget, use this kind of CSS

    this->setStyleSheet(
                "#centralWidget { "
                " border-image: url(:/background.png) 0 0 0 0 stretch stretch;"
                "}");
    

提交回复
热议问题