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. How set background image for QDialog?
QtWS25 Last Chance

How set background image for QDialog?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.0k Views
  • 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    How set background image for QDialog?
    It ie not work:

            self.dialogRegistration = QDialog(self)
            self.dialogRegistration.setFixedWidth(500)
            self.dialogRegistration.setMinimumHeight(500)
            pal = QPalette()
            background = QImage("./images/Fon.png")
            background2 = background.scaled(QSize(500, 500))
            brush = QBrush(background2)
            pal.setBrush(QPalette.Background, brush)
            self.dialogRegistration.setAutoFillBackground(True)
            self.dialogRegistration.setPalette(pal)
    

    And if do this, then all widgets have background image, but me need set background image only for QDialog

    self.dialogRegistration.setStyleSheet("border-image: url(./images/Fon.png) stretch;")
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by
      #2

      It's magic work:

              styleSheet = self.dialogRegistration.styleSheet()
              styleSheet += "; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;"
              self.dialogRegistration.setStyleSheet(styleSheet)
              styleSheet.replace("; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;", "")
             
      
             lineEditName.setStyleSheet("background-color: rgb(16,40,84); border-image: url(./images/________.png) stretch;")
              
      
      Thank YouT 1 Reply Last reply
      0
      • M Mikeeeeee

        It's magic work:

                styleSheet = self.dialogRegistration.styleSheet()
                styleSheet += "; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;"
                self.dialogRegistration.setStyleSheet(styleSheet)
                styleSheet.replace("; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;", "")
               
        
               lineEditName.setStyleSheet("background-color: rgb(16,40,84); border-image: url(./images/________.png) stretch;")
                
        
        Thank YouT Offline
        Thank YouT Offline
        Thank You
        wrote on last edited by
        #3

        @Mikeeeeee if I understand your question then it is preety simple
        just use stylesheet with

        someThingWidget.setStylesheet("
        #someThingWidget{\
        border-image:url("location of image");\
        }\
        ");
        

        replace location of image with valid url. I would recommend you to use image in resources file.
        It's stylesheet way to solve this problem
        Thank you

        Let's make QT free or It will go forever

        TRUE AND FALSE <3

        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