简体   繁体   中英

pyQt Radio Buttons: Adjusting size of buttons and text

I'm trying to adjust the size of both the button and the text of a radio button widget in PyQt, with no luck at trying to do both.

With this bit of code:

radioButton = QRadioButton(options[x]['desc'])
radioButton.setStyleSheet('font: 16pt Helvetica MS; QRadioButton::indicator { width: 30px; height: 30px;};')

I get this:

small buttons, big text

but when I do this:

radioButton = QRadioButton(options[x]['desc'])
radioButton.setStyleSheet('QRadioButton::indicator { width: 30px; height: 30px;};')

I get this:

Big Buttons, Small Text

So what is the correct way to combine statements to get the Big Buttons/Big Text combination?

You have to use {}

'QRadioButton{properties} QRadioButton::indicator{properties};'

Example:

from PyQt5.QtWidgets import *

if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    f = QFrame()
    f.setLayout(QVBoxLayout())
    for i in range(4):
        r = QRadioButton("opt{}".format(i), f)
        r.setStyleSheet('QRadioButton{font: 30pt Helvetica MS;} QRadioButton::indicator { width: 30px; height: 30px;};')
        f.layout().addWidget(r)
    f.show()
    sys.exit(app.exec_())

在此处输入图片说明

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