Search code examples
pythonpyqt5qt-designerqtstylesheets

Stylesheet QmainWindow does not work on pyqt5, only qt designer preview


stylesheet Qt designer:

QMainWindow {
                
    background-image: url(:/tela/app_imagens/kawaii-1546834.png);
                background-repeat: no-repeat; 
                background-position: center;
 }

In the preview of the qt designer the stylesheet works normally:

qt

however when running the application nothing appears:

app


Solution

  • What happens is that Qt Designer compiles the .qrc and imports it unlike your script which does not. The solution is:

    1. Compile the .qrc:
    pyrcc5 file.qrc -o file_rc.py
    
    1. and import it into your .py:
    import file_rc