Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Background image

Background image

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 570 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sashup
    wrote on last edited by
    #1

    How can I made background image? I use some thing but it doesn't help

    import sys
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class ClassesPage1(QtWidgets.QWizardPage):
        def __init__(self, *args, **kwargs):
            super(ClassesPage1, self).__init__(*args, **kwargs)
    
            self.setTitle("...")
            self.setSubTitle("...")
    
            #self.setStyleSheet("background-color: rgb(100, 133, 202);")
    
            self.checkBox_1 = QtWidgets.QCheckBox('...')
            self.checkBox_2 = QtWidgets.QCheckBox('...')
            self.checkBox_3 = QtWidgets.QCheckBox('...')
            self.checkBox_4 = QtWidgets.QCheckBox('...')
    
            self.layout = QtWidgets.QVBoxLayout()
            self.layout.addWidget(self.checkBox_1)
            self.layout.addWidget(self.checkBox_2)
            self.layout.addWidget(self.checkBox_3)
            self.layout.addWidget(self.checkBox_4)
            self.setLayout(self.layout)
    
            self.checkBox_1.stateChanged.connect(self.check)
            self.checkBox_2.stateChanged.connect(self.check)
            self.checkBox_3.stateChanged.connect(self.check)
            self.checkBox_4.stateChanged.connect(self.check)
            
            self.listCheckBox = [self.checkBox_1, self.checkBox_2, self.checkBox_3, self.checkBox_4] 
            self.a = 0                                                                                    
    
        def check(self, state):
            self.a = 0                                               
            if state == Qt.Checked:
                a = a + 1
            for checkBox in self.listCheckBox:                       
                if checkBox.isChecked():                              
                    self.a += 1                                      
            print(self.a)
    
        def nextId(self):
            return Wizard.class4
    
    stylesheet = '''
        QWidget {
            background-image: url("C:\111.jpg");
        }
    '''
            
        if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        app.setStyleSheet(stylesheet)
        w = ClassesPage1()
        w.show()
        sys.exit(app.exec_()) 
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      @sashup said in Background image:

      background-image: url("C:\111.jpg");

      The path is invalid. You are escaping the 1 with that backslash.

      Either properly escape it or use forward slashes since Qt provides support for them on all platforms.

      Use forward slashes, it's the only variant that is supported in QSS.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        @sashup said in Background image:

        background-image: url("C:\111.jpg");

        The path is invalid. You are escaping the 1 with that backslash.

        Either properly escape it or use forward slashes since Qt provides support for them on all platforms.

        Use forward slashes, it's the only variant that is supported in QSS.

        S Offline
        S Offline
        sashup
        wrote on last edited by
        #3

        @SGaist For example, background-image: url("C:/bbb.jpg"); but it doesn't work

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Is the image file valid ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            Is the image file valid ?

            S Offline
            S Offline
            sashup
            wrote on last edited by
            #5

            @SGaist Yes, thanks. I try another picture

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You can check that it's valid by loading it in a QLabel.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved