Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QLabel padding not applied when unpolish, polished
Qt 6.11 is out! See what's new in the release blog

QLabel padding not applied when unpolish, polished

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 447 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.
  • H Offline
    H Offline
    HyunYoung
    wrote on last edited by
    #1

    I define style sheet and test.py like below.

    I expected the label's text padding change 10px -> 100px but its not applied. The background color changed to RED. I test color, font-size as well, but only 'padding' didn't applied after click the button.

    Can anyone explain why only padding not applied in style sheet?

    style

    .QLabel[text="OK"]{
      background-color: rgb(0,255,0);
        color: rgb(255,250,250);
        font-size: 24pt;
        padding: 10px;
    }
    
    .QLabel[text="ERR"]{
      background-color: rgb(255,0,0);
        color: rgb(255,250,250);
        font-size: 24pt;
        padding: 100px;
    }
    

    test.py

    from PySide6 import QtWidgets
    from PySide6.QtCore import Qt
    
    
    class MyWindow(QtWidgets.QWidget):
        def set_style(self):
            with open('./style', 'r') as f:
                self.setStyleSheet(f.read())
    
        def __init__(self):
            super().__init__()
    
            self.set_style()
            self.setupUi()
    
        def setupUi(self):
            self.label = QtWidgets.QLabel('OK', self)
            self.label.setAlignment(Qt.AlignCenter)
            self.button = QtWidgets.QPushButton('Button', self)
    
            vlayout = QtWidgets.QVBoxLayout(self)
            vlayout.setAlignment(Qt.AlignCenter)
            vlayout.addWidget(self.label)
            vlayout.addWidget(self.button)
    
            self.button.clicked.connect(self.btn_clicked)
    
            self.show()
    
        def btn_clicked(self, a):
            self.label.setText("ERR")
            self.label.style().unpolish(self.label)
            self.label.style().polish(self.label)
            self.update()
    
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication([])
        win = MyWindow()
        app.exec_()
    
    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