To keep the GUI widgets number to minimum I need to find a way to give to user a choice of pull-down menu items that could be used to filter out the displayed in a listWidge
(Not an answere to the question, hence I used most of the code from here)
I added a function and changed the name to RadioComboBox if anyone else wants to have a class for a RadioComboBox.
from PyQt4 import QtCore
from PyQt4.QtGui import QComboBox, QStandardItemModel
class RadioComboBox(QComboBox):
def __init__(self):
super(RadioComboBox, self).__init__()
self.view().pressed.connect(self.handle_item_pressed)
self.setModel(QStandardItemModel(self))
def handle_item_pressed(self, index):
item = self.model().itemFromIndex(index)
target_row = item.index().row()
if item.checkState() != QtCore.Qt.Checked:
item.setCheckState(QtCore.Qt.Checked)
self.check_others(target_row)
def check_others(self, target_row):
for i in range(self.model().rowCount()):
if i == target_row:
continue
else:
item = self.model().item(i)
item.setCheckState(QtCore.Qt.Unchecked)