Skip to content

Commit

Permalink
using strict enums for QlistWidgetItem
Browse files Browse the repository at this point in the history
  • Loading branch information
seb5g committed Oct 29, 2024
1 parent 7c92720 commit 8e5e871
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pymodaq_gui/parameter/pymodaq_ptypes/itemselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class ItemSelect(QtWidgets.QListWidget):
def __init__(self, hasCheckbox=True):
QtWidgets.QListWidget.__init__(self)
self.hasCheckbox = hasCheckbox # Boolean indicating if listwidget item uses checkbox ot not
self.selItems = [] # Dummy variable to keep track of click order
self.selItems = [] # Dummy variable to keep track of click order
self.itemDoubleClicked.connect(self.doubleClickSelection)

def doubleClickSelection(self,item:QtWidgets.QListWidgetItem):
def doubleClickSelection(self, item: QtWidgets.QListWidgetItem):
"""
Function to select item. The selection depends if the item uses checkbox or not.
"""
if self.hasCheckbox:
item.setCheckState(int(2*bool(not item.checkState())))

item.setCheckState(QtCore.Qt.Checked if item.checkState() == QtCore.Qt.Unchecked
else QtCore.Qt.Unchecked)

def get_value(self):
"""
Expand Down Expand Up @@ -101,7 +101,7 @@ def select_item(self, item: QtWidgets.QListWidgetItem, doSelect:bool = False):
Function to select item. The selection depends if the item uses checkbox or not.
"""
if self.hasCheckbox:
item.setCheckState(int(2*doSelect)) # 2=QtCore.Qt.Checked, 0=QtCore.Qt.Unchecked
item.setCheckState(QtCore.Qt.Checked if doSelect else QtCore.Qt.Unchecked) # 2=QtCore.Qt.Checked, 0=QtCore.Qt.Unchecked
else:
item.setSelected(doSelect)

Expand Down

0 comments on commit 8e5e871

Please sign in to comment.