-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiselect.py
52 lines (45 loc) · 1.34 KB
/
multiselect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'''
Created on 6 Nov 2017
@author: jimmy
'''
from PySide2 import QtWidgets
class Multiselect(QtWidgets.QToolButton):
'''
classdocs
'''
def __init__(self, title):
'''
Constructor
'''
super(Multiselect, self).__init__()
self.setText(title)
self.choiceMenu = QtWidgets.QMenu(self)
self.setMenu(self.choiceMenu)
self.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)
self.clicked.connect(self.showMenu)
def updateChoices(self, choices):
'''
Update the Choices
@param choices: List of choices
'''
oldChoices = []
for action in self.choiceMenu.actions():
oldChoices.append(action.text())
# self.choiceMenu.clear()
for choice in choices:
if choice not in oldChoices:
action = self.choiceMenu.addAction(choice)
action.setCheckable(True)
def setChoice(self, choice, checked):
for action in self.choiceMenu.actions():
if action.text() == choice:
action.setChecked(checked)
def getCheckedChoices(self):
'''
Get the choices
'''
values = []
for action in self.choiceMenu.actions():
if action.isChecked():
values.append(action.text())
return values