pyqt5学习之QRadioButton

QRadioButton继承于QAbstractButton;一般用于给用户提供若干选项中的单选操作
案例
from PyQt5.Qt import *
import sys

app = QApplication(sys.argv)

window = QWidget()
window.setWindowTitle('QRadioButton-功能测试')
window.resize(500, 500)

red = QWidget(window)
red.resize(200,200)
red.setStyleSheet('background-colour: red;')
red.move(50, 50)

green = QWidget(window)
green.resize(200, 200)
green.setStyleSheet("background-color: green;")
green.move(red.x() + red.width(), red.y() + red.height())

rb_nan = QRadioButton('', red) #设置QRadioButton方法
rb_nan.setShortcut('alt+a')  # 设置快捷键
rb_nan.move(10, 10)
rb_nan.setChecked(True)

rb_nv = QRadioButton("女-&Female", red)
rb_nv.move(10, 50)
rb_nv.setIcon(QIcon("dp.png"))
rb_nv.setIconSize(QSize(60, 60))
rb_nv.toggled.connect(lambda isChecked: print(isChecked))  #常用信号

rb_yes = QRadioButton("yes", green)
rb_yes.move(10, 10)
rb_no = QRadioButton("no", green)
rb_no.move(10, 50)



window.show()

sys.exit(app.exec_())
View Code

 

posted @ 2020-03-18 07:13  墨色无墨  阅读(754)  评论(0编辑  收藏  举报