from PyQt5.QtWidgets import QMainWindow, QHBoxLayout, QApplication, QWidget, QRadioButton
from PyQt5.QtCore import pyqtSlot, Qt, QRect, QSize, QTimer
import sys
class MyRadio(QRadioButton):
def __init__(self, text, parent = None):
super(MyRadio, self).__init__(parent)
self.setStyleSheet("QRadioButton::indicator:checked {border-image: url(./img/select.png);}"
"QRadioButton::indicator:unchecked {border-image: url(./img/unselect.png);}")
self.setText(text)
class WinForm(QMainWindow):
def __init__(self, parent=None):
super(WinForm, self).__init__(parent)
self.setWindowTitle('test')
self.button1 = MyRadio('123')
layout = QHBoxLayout()
layout.addWidget(self.button1)
main_frame = QWidget()
main_frame.setLayout(layout)
self.setCentralWidget(main_frame)
if __name__ == "__main__":
App = QApplication(sys.argv)
form = WinForm()
form.show()
sys.exit(App.exec_())
图片:
效果: