Important: Please read the Qt Code of Conduct -

Could not make background image not to repeat

  • I am puzzled why it did not use background-repeat to no-repeat. It kept appearing repeating in the both directions. Maybe you could catch something that I overlooked. Basically this works as background image and I was able to put controls over the image. I just need the image to be non-repeat.
    Here is the code as follows:

    class displayImage(QtWidgets.QDialog):

    def init(self,parent=None):
    super(displayImage, self).init()

        oImage = QtGui.QImage("C:/imagefilename.bmp")
        self.setStyleSheet("background-image: url(oImage); background-repeat: no-repeat; background-position: left;")
        # sImage = oImage.scaled(QtCore.QSize(75,250))                   # resize Image to widgets size
        palette = QtGui.QPalette()
        palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(oImage))

  • Moderators

    What version of qt are you using?

  • @J-Hilk
    I am a newbie. I am not quite sure but I believe I am using qt using PySide2 binding. I am using to develop GUI for Maya. That is the only way it got working.

  • Moderators

    Qt as a framework, comes in many different versions. (Also as bindings for python)

    you can simply print QT_VERSION to check at run time, I don't know how else you would check it as I'm not familiar with Python.
    something like this:

    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        qDebug() << QString::number(QT_VERSION,16); // Result will be 50C06 -> Qt 5.12.6
        return  a.exec();

    I'm asking, because there was a bug with stylesheets, and those were not correctly applied to the widgets. That was fixed in the newest versions, 5.12.6 and 5.13.2

  • @J-Hilk Yes I did something different for Python and Maya It appears that PySide2 uses PyQt5 5.6.1 binding

  • Moderators

    @autoasl said in Could not make background image not to repeat:


    Interesting, from the official side, it should be 5.12.6 🤔

    I however, can not further help you, I'm sure someone else has more experience with Images as background Brush :)

  • @J-Hilk Thank you for pointing out what is the root cause. I'll try investigating more. I see one from the Internet "Maya 2019 uses Qt5.6.1 which is binary compatible with the latest version of PyQt 5.11.3 / SIP - 4.19.13" I may need to try upgrade if I can

Log in to reply