简体   繁体   中英

How can i change the font size of the checkbox Name

Here is my code, i want to change font size of the checkbox name and increase the boarded size of the comboBOx, i tried like this but i am not getting the output properly.Can you please guide me how to change the size of the font

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()

Sorry, I have PyQt5 Try it:

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()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM