如何从groupBox更改子QLabel小部件的字体大小

如何使用不同的字体和GroupBox中的子窗口小部件的大小和python中的GroupBox的小部件

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

我累了

   self.Voltage_Label.setFont(QtGui.QFont('SansSerif', 10))

我收到这个错误

    !! self.Voltage_Label.setFont(QtGui.QFont('SansSerif', 10))
AttributeError: 'list' object has no attribute 'setFont' !!

但对于像thistitle1 = QtGui.QLabel(“Sample Title”)这样的东西,我可以改变它

 title1.setFont(QtGui.QFont('SansSerif', 10))
最佳答案
当我在等待答案时,我想尝试一下,并为我的问题找到了这个方法/解决方案:

self.Voltage_Label = []

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 "))
.
.

for i in xrange(5):
        newfont = QtGui.QFont("Times", 8, QtGui.QFont.Bold) 
        self.Voltage_Label[i].setFont(newfont)

转载注明原文:如何从groupBox更改子QLabel小部件的字体大小 - 代码日志