How set Title of QgroupBox to bold
-
-
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 :)
-
-
@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 viaQGroupBox::title
. The following worksself.group.setStyleSheet("QGroupBox { font-size: 18px; font-weight: bold; }")
-
If stylesheets aren't working out for you, you can get a copy of
QGroupBox
's currentfont
(you'll get aQtQui.QFont
object), set it tobold
, then set the newbold font
:grp_bold = QtWidgets.QGroupBox("Look How Bold I Am!") fnt_group = grp_bold.font() fnt_group.setBold(True) grp_bold.setFont(fnt_group)