如何更改复选框名称的字体大小
How can i change the font size of the checkbox Name
这是我的代码,我想更改复选框名称的字体大小并增加组合框的登机大小,我试过这样但我没有得到输出 properly.Can 请指导我如何操作更改字体大小
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()
抱歉,我有 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()
这是我的代码,我想更改复选框名称的字体大小并增加组合框的登机大小,我试过这样但我没有得到输出 properly.Can 请指导我如何操作更改字体大小
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()
抱歉,我有 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()