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?
Forum Updated to NodeBB v4.3 + New Features

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 20 May 2021, 08:18 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 20 May 2021, 09:02 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;")
              
      
      T 1 Reply Last reply 23 May 2021, 03:26
      0
      • M Mikeeeeee
        20 May 2021, 09:02

        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;")
                
        
        T Offline
        T Offline
        Thank You
        wrote on 23 May 2021, 03:26 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

        2/3

        20 May 2021, 09:02

        • Login

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