PyQt4:QWidget子类中具有autoexclusive属性的QRadioButton

2024-04-25 02:13:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了一个名为RadioSpinButtonQWidget子类,在PyQt4的Python应用程序中,它由QSpinBox旁边的QRadioButton组成。我在一个水平布局中使用一个RadioSpinButton的实例,其中有两个QRadioButton实例。新类中的QRadioButton具有其他两个QRadioButton的相同父级,但其autoExclusive属性不起作用。我怎样才能解决这个问题?我只需要检查一个按钮,但我有这个:

{1美元^

enter image description here

编码

from PyQt4 import QtCore, QtGui

class NewProject(QtGui.QWizard):
    def __init__(self, parent=None):
        super(NewProject, self).__init__(parent)

        # Iniciando páginas
        self.init_filepage()

        # Tamaño mínimo de la ventana
        #self.setMinimumSize(800, 600)

        # Título
        self.setWindowTitle(self.tr('Nuevo Proyecto'))

    def init_filepage(self):
        # Página para selección de imágenes
        self.addPage(FilesPage(self))    

class FilesPage(QtGui.QWizardPage):
    def __init__(self, parent=None):
        super(FilesPage, self).__init__(parent)

        # Título de la página
        self.setTitle(self.tr('Imagen'))
        self.setSubTitle(self.tr('Seleccione la escena alrededor de la cual se construirá el proyecto.'))
        #self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/app-icon.svg").scaledToHeight(48))

        # Elementos
        # Tipo de imagen según la cantidad de bandas
        imgtype = QtGui.QGroupBox(self.tr('Tipo de imagen (cantidad de bandas):'))
        imgtypelayout = QtGui.QHBoxLayout()

        imgPANtype = QtGui.QRadioButton(self.tr('PAN (1 banda)'), self)
        imgtypelayout.addWidget(imgPANtype)

        imgMSStype = QtGui.QRadioButton(self.tr('MSS (4 bandas)'), self)
        imgtypelayout.addWidget(imgMSStype)

        imgVartype = RadioSpinButton(self.tr('Variable'), self)
        imgtypelayout.addWidget(imgVartype)

        imgtype.setLayout(imgtypelayout)

        # Disposición principal
        layout = QtGui.QVBoxLayout()
        layout.addWidget(imgtype)

        self.setLayout(layout)    

class RadioSpinButton(QtGui.QWidget):
    def __init__(self, text, parent=None):
        super(RadioSpinButton, self).__init__(parent)

        # Radiobutton
        self.button = QtGui.QRadioButton(text, parent)
        self.button.toggled.connect(self.change_spinbox)

        # Spinbox
        self.spinbox = QtGui.QSpinBox()
        self.spinbox.setEnabled(False)

        # Disposición
        layout = QtGui.QHBoxLayout()
        layout.addWidget(self.button)
        layout.addWidget(self.spinbox)
        self.setLayout(layout)

    @QtCore.pyqtSlot()
    def change_spinbox(self):
        self.spinbox.setEnabled(not self.spinbox.isEnabled())

这是设计RadioSpinButton子类的正确方法吗?在


Tags: selfinitdefdetrlaclassparent