Skip to content
Permalink
Browse files

Add context menu with Select All/Clear Selection to checkboxes panel

  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 5ee3239 commit 95ab2321e5bc011dc26735748bdd9b5a3890a803
Showing with 26 additions and 1 deletion.
  1. +26 −1 python/plugins/processing/gui/CheckboxesPanel.py
@@ -26,7 +26,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (
QCheckBox,
QRadioButton,
@@ -35,7 +35,10 @@
QSizePolicy,
QSpacerItem,
QWidget,
QMenu,
QAction
)
from qgis.PyQt.QtGui import QCursor


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

if multiple:
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showPopupMenu)

def showPopupMenu(self):
popup_menu = QMenu()
select_all_action = QAction(self.tr('Select All'), popup_menu)
select_all_action.triggered.connect(self.selectAll)
clear_all_action = QAction(self.tr('Clear Selection'), popup_menu)
clear_all_action.triggered.connect(self.deselectAll)
popup_menu.addAction(select_all_action)
popup_menu.addAction(clear_all_action)
popup_menu.exec_(QCursor.pos())

def selectAll(self):
for (v, button) in self._buttons:
button.setChecked(True)

def deselectAll(self):
for (v, button) in self._buttons:
button.setChecked(False)

def value(self):
if self._multiple:
value = []

0 comments on commit 95ab232

Please sign in to comment.
You can’t perform that action at this time.