这是我的代码,我想更改复选框名称的字体大小并增加comboBOx的面板大小,我试图这样做,但我没有得到正确的输出。请您指导我如何更改大小字体
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
vbox = QtGui.QVBoxLayout()
cb = QtGui.QCheckBox('Show title', self)
cb.move(20, 20)
cb.toggle()
frequencycb = QtGui.QComboBox()
frequencycb.addItems(["30KHZ", "60KHZ","120KHZ","300KHZ","0.6MHZ", "1.2MHZ","3MHZ","6MHZ"])
vbox.addWidget(cb)
vbox.addWidget(frequencycb)
self.setLayout(vbox)
cb.stateChanged.connect(self.changeTitle)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('QtGui.QCheckBox')
self.show()
def changeTitle(self, state):
if state == QtCore.Qt.Checked:
self.setWindowTitle('QtGui.QCheckBox')
else:
self.setWindowTitle('')
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
答案 0 :(得分:1)
对不起,我有PyQt5 试试吧:
import sys
#from PySide import QtGui, QtCore
from PyQt5 import Qt
class Example(Qt.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
vbox = Qt.QVBoxLayout()
cb = Qt.QCheckBox('Show title', self)
cb.move(20, 20)
cb.toggle()
frequencycb = Qt.QComboBox()
frequencycb.addItems(["30KHZ", "60KHZ","120KHZ","300KHZ","0.6MHZ", "1.2MHZ","3MHZ","6MHZ"])
vbox.addWidget(cb)
vbox.addWidget(frequencycb)
self.setLayout(vbox)
cb.stateChanged.connect(self.changeTitle)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('QtGui.QCheckBox')
self.show()
def changeTitle(self, state):
if state == Qt.Qt.Checked:
self.setWindowTitle('QtGui.QCheckBox')
else:
self.setWindowTitle('')
StyleSheet = '''
QCheckBox {
spacing: 5px;
font-size:25px; /* <--- */
}
QCheckBox::indicator {
width: 33px;
height: 33px;
}
'''
def main():
app = Qt.QApplication(sys.argv)
app.setStyle("fusion") # +++
app.setStyleSheet(StyleSheet)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()