I’m trying to use 2 sets of QRadioButton(s) that select different attributes.
The snippet of the code reads:
self.imum_box = QHBoxLayout()
pigmemti_box = QHBoxLayout() # First set of QRadioButtons for attribute ‘Font color’
self.nuntium_1 = QLabel("Font color")
pigmemti_box.addWidget(self.nuntium_1)
self.t_albinus = QRadioButton("White",self)
self.t_albinus.setChecked(True)
self.t_albinus.toggled.connect(self.pigmemtum_has_changed)
self.t_nigreos = QRadioButton("Black",self)
self.t_nigreos.toggled.connect(self.pigmemtum_has_changed)
pigmemti_box.addWidget(self.t_albinus)
pigmemti_box.addWidget(self.t_nigreos)
self.etiqueta = QLabel(" ")
pigmemti_box.addWidget(self.etiqueta)
palette_box = QHBoxLayout() # Second set of QRadioButtons for attribute ‘Color palette’
self.nuntium_2 = QLabel("Color palette")
palette_box.addWidget(self.nuntium_2)
self.red_blue = QRadioButton("Blue and red",self)
self.red_blue.setChecked(True)
self.red_blue.toggled.connect(self.palette_has_changed)
palette_box.addWidget(self.red_blue)
self.echo_tops = QRadioButton("Echo tops",self)
self.echo_tops.setChecked(False)
self.echo_tops.toggled.connect(self.palette_has_changed)
palette_box.addWidget(self.echo_tops)
self.black_white = QRadioButton("Black and white",self)
self.black_white.setChecked(False)
self.black_white.toggled.connect(self.palette_has_changed)
palette_box.addWidget(self.black_white)
self.imum_box.addLayout(pigmemti_box)
self.imum_box.addLayout(palette_box)
self.tab1.setLayout(self.imum_box) # This line just adds the 2 set to the general layout
The problem is that even though the QRadioButton(s) belong to different sets (and different layouts), they are still interfering. For example, if I check on ‘White’ , it will uncheck ‘Blue and red’ even though they are not supposed to be connected. The same problem happens if I check ‘Echo tops’ as it will uncheck ‘White’ or ‘Black.’ Not sure why this behavior.
Addendum: I also tried QButtonGroup with the following snippet:
self.imum_box = QHBoxLayout()
classis_pigmemti = QButtonGroup()
pigmemti_box = QHBoxLayout()
self.nuntium_1 = QLabel("Font color")
pigmemti_box.addWidget(self.nuntium_1)
self.t_albinus = QRadioButton("White",self)
self.t_albinus.setChecked(True)
self.t_nigreos = QRadioButton("Black",self)
pigmemti_box.addWidget(self.t_albinus)
pigmemti_box.addWidget(self.t_nigreos)
classis_pigmemti.addButton(self.t_albinus)
classis_pigmemti.addButton(self.t_nigreos)
palette_box = QHBoxLayout()
classis_palette = QButtonGroup()
self.nuntium_2 = QLabel("Color palette")
palette_box.addWidget(self.nuntium_2)
self.red_blue = QRadioButton("Blue and red",self)
self.red_blue.setChecked(True)
palette_box.addWidget(self.red_blue)
self.echo_tops = QRadioButton("Echo tops",self)
self.echo_tops.setChecked(False)
palette_box.addWidget(self.echo_tops)
self.black_white = QRadioButton("Black and white",self)
self.black_white.setChecked(False)
palette_box.addWidget(self.black_white)
classis_palette.addButton(self.red_blue)
classis_palette.addButton(self.echo_tops)
classis_palette.addButton(self.black_white)
self.imum_box.addLayout(pigmemti_box)
self.imum_box.addLayout(palette_box)
self.tab1.setLayout(self.imum_box)
However, this didn’t work either as it is possible to select 2 elements from the same set with none from the other.