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. QDialog border inherited by child QCheckBox
Forum Updated to NodeBB v4.3 + New Features

QDialog border inherited by child QCheckBox

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 169 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.
  • C Offline
    C Offline
    Captain Haddock
    wrote on last edited by Captain Haddock
    #1

    I create a custom QDialog and specify a border in the stylesheet. The dialog has a QCheckBox that I have increased in size. The dialog border style also gets applied to the QCheckBox .. how can I stop the border being applied to the checkbox?

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtWidgets import *
    
    class MyDialog(QDialog):
    
        def __init__(self, parent=None):
            super(MyDialog, self).__init__(parent)
            self.setFixedSize(400, 400)
            self.setStyleSheet("background-color:#4C535D;border-style:solid;border-color: #E1D8FF;border-width:2px;border-radius:6px")
            self.myCheckBox = QCheckBox()
            self.myCheckBox.setStyleSheet("QCheckBox::indicator { width: 30px; height: 30px }")
            layout = QHBoxLayout()
            layout.addWidget(self.myCheckBox)
            self.setLayout(layout)
    
    def window():
        app = QApplication(sys.argv)
        w = QWidget()
        btn = QPushButton(w)
        btn.setText("Choose Me")
        btn.move(100,50)
        btn.clicked.connect(showdialog)
        w.setWindowTitle("PyQt Dialog demo")
        w.show()
        sys.exit(app.exec_())
    
    def showdialog():
        dlg = MyDialog()
        dlg.setWindowTitle("Dialog")
        dlg.setWindowModality(Qt.ApplicationModal)
        dlg.exec_()
    
    
    if __name__ == '__main__':
        window()
    
    
    JonBJ 1 Reply Last reply
    0
    • C Captain Haddock

      I create a custom QDialog and specify a border in the stylesheet. The dialog has a QCheckBox that I have increased in size. The dialog border style also gets applied to the QCheckBox .. how can I stop the border being applied to the checkbox?

      import sys
      from PyQt5.QtCore import *
      from PyQt5.QtWidgets import *
      
      class MyDialog(QDialog):
      
          def __init__(self, parent=None):
              super(MyDialog, self).__init__(parent)
              self.setFixedSize(400, 400)
              self.setStyleSheet("background-color:#4C535D;border-style:solid;border-color: #E1D8FF;border-width:2px;border-radius:6px")
              self.myCheckBox = QCheckBox()
              self.myCheckBox.setStyleSheet("QCheckBox::indicator { width: 30px; height: 30px }")
              layout = QHBoxLayout()
              layout.addWidget(self.myCheckBox)
              self.setLayout(layout)
      
      def window():
          app = QApplication(sys.argv)
          w = QWidget()
          btn = QPushButton(w)
          btn.setText("Choose Me")
          btn.move(100,50)
          btn.clicked.connect(showdialog)
          w.setWindowTitle("PyQt Dialog demo")
          w.show()
          sys.exit(app.exec_())
      
      def showdialog():
          dlg = MyDialog()
          dlg.setWindowTitle("Dialog")
          dlg.setWindowModality(Qt.ApplicationModal)
          dlg.exec_()
      
      
      if __name__ == '__main__':
          window()
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Captain-Haddock

      self.setStyleSheet("MyDialog { background-color:#4C535D; ... }")
      

      I believe should prevent that inheritance?

      1 Reply Last reply
      1
      • C Captain Haddock has marked this topic as solved on

      • Login

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