简体   繁体   English

pyQt 单选按钮:调整按钮和文本的大小

[英]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.我正在尝试在 PyQt 中调整按钮的大小和单选按钮小部件的文本,但都没有成功。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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