Skip to content

Commit 95ab232

Browse files
committed
Add context menu with Select All/Clear Selection to checkboxes panel
1 parent 5ee3239 commit 95ab232

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

python/plugins/processing/gui/CheckboxesPanel.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# This will get replaced with a git SHA1 when you do a git archive
2727
__revision__ = '$Format:%H$'
2828

29-
29+
from qgis.PyQt.QtCore import Qt
3030
from qgis.PyQt.QtWidgets import (
3131
QCheckBox,
3232
QRadioButton,
@@ -35,7 +35,10 @@
3535
QSizePolicy,
3636
QSpacerItem,
3737
QWidget,
38+
QMenu,
39+
QAction
3840
)
41+
from qgis.PyQt.QtGui import QCursor
3942

4043

4144
class CheckboxesPanel(QWidget):
@@ -70,6 +73,28 @@ def __init__(self, options, multiple, columns=2, parent=None):
7073
0, columns)
7174
self.setLayout(layout)
7275

76+
if multiple:
77+
self.setContextMenuPolicy(Qt.CustomContextMenu)
78+
self.customContextMenuRequested.connect(self.showPopupMenu)
79+
80+
def showPopupMenu(self):
81+
popup_menu = QMenu()
82+
select_all_action = QAction(self.tr('Select All'), popup_menu)
83+
select_all_action.triggered.connect(self.selectAll)
84+
clear_all_action = QAction(self.tr('Clear Selection'), popup_menu)
85+
clear_all_action.triggered.connect(self.deselectAll)
86+
popup_menu.addAction(select_all_action)
87+
popup_menu.addAction(clear_all_action)
88+
popup_menu.exec_(QCursor.pos())
89+
90+
def selectAll(self):
91+
for (v, button) in self._buttons:
92+
button.setChecked(True)
93+
94+
def deselectAll(self):
95+
for (v, button) in self._buttons:
96+
button.setChecked(False)
97+
7398
def value(self):
7499
if self._multiple:
75100
value = []

0 commit comments

Comments
 (0)