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. How set Title of QgroupBox to bold
Forum Updated to NodeBB v4.3 + New Features

How set Title of QgroupBox to bold

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 4 Posters 1.2k 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.
  • D Offline
    D Offline
    denis13
    wrote on last edited by
    #1

    Hello everybody,

    I would like to set the title of a QgroupBox in Qt 5.15 using python to bold but I can't find how to do it

    Could Someone help me ?

    Thank you :)

    jsulmJ 1 Reply Last reply
    0
    • D denis13

      Hello everybody,

      I would like to set the title of a QgroupBox in Qt 5.15 using python to bold but I can't find how to do it

      Could Someone help me ?

      Thank you :)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @denis13 See https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qgroupbox

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • D Offline
        D Offline
        denis13
        wrote on last edited by
        #3

        Hello, it's not work with QtWidgets but maybe, I must have made a mistake

        This a snippet of code,

        import sys
        from PySide6.QtWidgets import QWidget,QVBoxLayout,QLabel,QApplication,QGroupBox
        from PySide6.QtCore import Qt
        
        class MyWidget(QWidget):
            def __init__(self):
                super().__init__()
                self.layout = QVBoxLayout(self)
                self.group = QGroupBox("title",self)
                self.group.setStyleSheet("""QGroupBox::title{font:bold;}""")
                self.layout_vbox = QVBoxLayout(self.group)
                self.label = QLabel("ok")
                self.layout_vbox.addWidget(self.label,alignment=Qt.AlignLeft)
                self.layout.addWidget(self.group)
        
        if __name__ == "__main__":
            app = QApplication()
            widget = MyWidget()
            widget.show()
            sys.exit(app.exec())
        

        Thanks to your kindness and your help :)

        JonBJ 1 Reply Last reply
        0
        • D denis13

          Hello, it's not work with QtWidgets but maybe, I must have made a mistake

          This a snippet of code,

          import sys
          from PySide6.QtWidgets import QWidget,QVBoxLayout,QLabel,QApplication,QGroupBox
          from PySide6.QtCore import Qt
          
          class MyWidget(QWidget):
              def __init__(self):
                  super().__init__()
                  self.layout = QVBoxLayout(self)
                  self.group = QGroupBox("title",self)
                  self.group.setStyleSheet("""QGroupBox::title{font:bold;}""")
                  self.layout_vbox = QVBoxLayout(self.group)
                  self.label = QLabel("ok")
                  self.layout_vbox.addWidget(self.label,alignment=Qt.AlignLeft)
                  self.layout.addWidget(self.group)
          
          if __name__ == "__main__":
              app = QApplication()
              widget = MyWidget()
              widget.show()
              sys.exit(app.exec())
          

          Thanks to your kindness and your help :)

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @denis13 said in How set Title of QgroupBox to bold:

          self.group.setStyleSheet("""QGroupBox::title{font:bold;}""")

          If it's to work at all you would not want those extra quotes. Try with self.group.setStyleSheet("QGroupBox::title{font:bold;}")?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            denis13
            wrote on last edited by
            #5

            it's the same effect, it's not work....

            JonBJ 1 Reply Last reply
            0
            • D denis13

              it's the same effect, it's not work....

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @denis13
              Don't know. First try the example for QGroupBox::title at https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qgroupbox and see if that has any effect? Maybe there is a problem setting the font with font:bold?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                denis13
                wrote on last edited by
                #7

                it's not work also however I use setStyleSheet in Python.....

                JonBJ 1 Reply Last reply
                0
                • D denis13

                  it's not work also however I use setStyleSheet in Python.....

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @denis13 said in How set Title of QgroupBox to bold:

                  it's not work also however I use setStyleSheet in Python.....

                  Well I don't know how you come up with that. I just tried the QGroupBox::title code at https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qgroupbox I suggested and I certainly see some effect.

                  Since if I try self.group.setStyleSheet("QGroupBox::title{font:bold 14px;background-color:red;}") I do see a red background you can see we are setting the right stylesheet rule. I can only conclude that you cannot change the font.

                  UPDATE
                  You can, but not via QGroupBox::title. The following works

                  self.group.setStyleSheet("QGroupBox { font-size: 18px; font-weight: bold; }")
                  
                  1 Reply Last reply
                  1
                  • M Offline
                    M Offline
                    mjiggidyj
                    wrote on last edited by mjiggidyj
                    #9

                    If stylesheets aren't working out for you, you can get a copy of QGroupBox's current font (you'll get a QtQui.QFont object), set it to bold, then set the new bold font:

                    grp_bold = QtWidgets.QGroupBox("Look How Bold I Am!")
                    fnt_group = grp_bold.font()
                    fnt_group.setBold(True)
                    grp_bold.setFont(fnt_group)
                    

                    Bold of you to assume

                    JonBJ 1 Reply Last reply
                    0
                    • M mjiggidyj

                      If stylesheets aren't working out for you, you can get a copy of QGroupBox's current font (you'll get a QtQui.QFont object), set it to bold, then set the new bold font:

                      grp_bold = QtWidgets.QGroupBox("Look How Bold I Am!")
                      fnt_group = grp_bold.font()
                      fnt_group.setBold(True)
                      grp_bold.setFont(fnt_group)
                      

                      Bold of you to assume

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @mjiggidyj Which is exactly what the stylesheet I posted does and it works.

                      M 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @mjiggidyj Which is exactly what the stylesheet I posted does and it works.

                        M Offline
                        M Offline
                        mjiggidyj
                        wrote on last edited by
                        #11

                        @JonB Oh no another option

                        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