@@ -55,33 +55,11 @@ def __init__(self, parent=None):
55
55
56
56
self .lstItems .setModel (QStandardItemModel ())
57
57
58
- self .lstItems .clicked .connect (self .handleCheckbox )
59
-
60
- def handleCheckbox (self , index ):
61
- model = self .lstItems .model ()
62
- clickedItem = model .itemFromIndex (index )
63
-
64
- prevIndex = None
65
- for i in range (model .rowCount ()):
66
- if model .item (i ).checkState () == Qt .Checked :
67
- prevIndex = i
68
- break
69
-
70
- if prevIndex is None :
71
- clickedItem .setCheckState (Qt .Checked )
72
- else :
73
- if self .chkAllowMultiple .isChecked ():
74
- clickedItem .setCheckState (Qt .Checked )
75
- else :
76
- model .item (prevIndex ).setCheckState (Qt .Unchecked )
77
- clickedItem .setCheckState (Qt .Checked )
78
-
79
58
def addItem (self ):
80
59
model = self .lstItems .model ()
81
60
82
61
item = QStandardItem ('new item' )
83
62
item .setCheckable (True )
84
- item .setCheckState (Qt .Unchecked )
85
63
item .setDropEnabled (False )
86
64
87
65
model .appendRow (item )
@@ -122,24 +100,19 @@ def allowMultiple(self):
122
100
def setOptions (self , options ):
123
101
model = self .lstItems .model ()
124
102
for i in options :
125
- item = QStandardItem ()
103
+ item = QStandardItem (i )
126
104
item .setCheckable (True )
127
- item .setCheckState (Qt .Unchecked )
128
105
item .setDropEnabled (False )
129
106
130
107
model .appendRow (item )
131
108
132
- def setDefault (self , index ):
109
+ def setDefault (self , indexes ):
133
110
model = self .lstItems .model ()
134
- item = model .item (index , 0 )
135
- if item :
136
- item .setCheckState (Qt .Checked )
111
+
112
+ for i in indexes :
113
+ item = model .item (i )
114
+ if item :
115
+ item .setCheckState (Qt .Checked )
137
116
138
117
def setAllowMultiple (self , allowMultiple ):
139
118
self .chkAllowMultiple .setChecked (allowMultiple )
140
-
141
- model = self .lstItems .model ()
142
- for i in range (model .rowCount ()):
143
- if model .item (i ).checkState () == Qt .Checked :
144
- model .item (i ).setCheckState (Qt .Unchecked )
145
- break
0 commit comments