QRadioButton:
描述:
一般用于给用户提供拖杆选项中的单选操作:
比如:
性别:(男;女)
答案:(是;否)
当选中一个时,会自动取消上一个
继承:QAbstractButton
功能作用:
创建单选按钮:
QRadioButton(parent)
QRadioButton(text, parent)
常用继承父类操作:
图标:setIcon(QIcon)
快捷键:
文本加该
setShortcut()
信号:
均继承自父类
常用信号为:toggled(bool)
from PyQt5.Qt import * import sys app = QApplication(sys.argv) window = QWidget() window.resize(300,300) window.setWindowTitle(‘QRadioButton-功能‘) red = QWidget(window) red.resize(100, 150) red.setStyleSheet(‘background-color: red;‘) red.move(50, 50) green = QWidget(window) green.resize(100, 100) green.setStyleSheet(‘background-color: green;‘) green.move(red.x() + red.width(), red.y() + red.height()) # rb_man = QRadioButton(‘男-&Male‘, window) # 设置快捷键 rb_man = QRadioButton(‘男‘, red) rb_man.setShortcut(‘Alt+M‘) # 设置快捷键 rb_man.move(10, 10) rb_man.setChecked(True) # rb_woman = QRadioButton(‘女-&FMale‘, window) rb_woman = QRadioButton(‘女‘, red) rb_woman.setShortcut(‘Alt+F‘) rb_woman.move(10, 40) rb_woman.setIcon(QIcon(‘click.jpg‘)) rb_woman.setIconSize(QSize(20, 20)) rb_woman.toggled.connect(lambda isChecked: print(isChecked)) # 状态更改函数 # rb_woman.setAutoExclusive(False) # 设立独占特性 rb_yes = QRadioButton(‘yes‘, green) rb_yes.move(0, 0) rb_no = QRadioButton(‘no‘, green) rb_no.move(0, 30) window.show() sys.exit(app.exec_())
原文:https://www.cnblogs.com/superSmall/p/12900331.html