How can use different font & size for the child Widgets in the GroupBox and the tittle for the GroupBox in python
def panel(self):
groupBox = QtGui.QGroupBox("voltage Monitor")
groupBox.setFont(QtGui.QFont('SansSerif', 13)) # the title size is good
..
self.Voltage_Label = []
..
vbox = QtGui.QGridLayout()
self.Voltage_Label.append(QtGui.QLabel("voltage1 ")) # i need to have diff Font & size for these
self.Voltage_Label.append(QtGui.QLabel("voltage2 "))
self.Voltage_Label.append(QtGui.QLabel("voltage3 "))
..
vbox.addWidget(self.Voltage_Label[i], i, 0)
..
groupBox.setLayout(vbox)
return groupBox
I tired this
self.Voltage_Label.setFont(QtGui.QFont('SansSerif', 10))
I get this error
!! self.Voltage_Label.setFont(QtGui.QFont('SansSerif', 10))
AttributeError: 'list' object has no attribute 'setFont' !!
but for something like thistitle1 = QtGui.QLabel("Sample Title")
as a child widget i can change it by
title1.setFont(QtGui.QFont('SansSerif', 10))
In this article, we will see how to change the font and size of the text in Label, we can do this by using setFont () method. 1. Font name it can be ‘Arial’, ‘Times’ etc.
Unless you set the font of a control it uses the font of it's parent container so yes you can but then you will have to set the font of all the controls in the groupbox . It is possible to select all of the controls in the groupbox and then set the font to change them all at once instead of one at a time .
To change the font of all QLabels then there are several options: custom_font = QFont () custom_font.setWeight (18); QApplication.setFont (custom_font, "QLabel") Oh, I never noted there's a class specifier to setFont now. When did they add that? Thanks for the addition.
The keyboard shortcut moves keyboard focus to one of the group box's child widgets. QGroupBox also lets you set the title (normally set in the constructor) and the title's alignment. Group boxes can be checkable.
also, you can try
font = QtGui.QFont("Times", 8, QtGui.QFont.Bold)
[label.setFont(font) for label in self.Voltage_Label]
if you are creating a font object every time you iterate over an item of self.Voltage_Label
it will cost you some memory. so, therefore, you can share the same one with all the labels. whenever memory matters you can use this technique. but if you want to change the font on all label
objects it won't change the font in other QLabel
objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With