From b2924ef9bb74bfce109c1d62c09ef04ccea2f4e5 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Thu, 2 May 2024 17:02:52 +0800 Subject: [PATCH] moninj: delete widget action --- artiq/dashboard/moninj.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/artiq/dashboard/moninj.py b/artiq/dashboard/moninj.py index 99a7e1164..78c2a28bb 100644 --- a/artiq/dashboard/moninj.py +++ b/artiq/dashboard/moninj.py @@ -835,6 +835,23 @@ class _MonInjDock(QDockWidgetCloseDetect): self.flow = DragDropFlowLayoutWidget() scroll_area.setWidgetResizable(True) scroll_area.setWidget(self.flow) + self.flow.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.flow.customContextMenuRequested.connect(self.custom_context_menu) + + def custom_context_menu(self, pos): + index = self.flow._get_index(pos) + if index == -1: + return + menu = QtWidgets.QMenu() + delete_action = QtWidgets.QAction("Delete widget", menu) + delete_action.triggered.connect(partial(self.delete_widget, index)) + menu.addAction(delete_action) + menu.exec_(self.flow.mapToGlobal(pos)) + + def delete_widget(self, index, checked): + widget = self.flow.itemAt(index).widget() + widget.hide() + self.flow.layout.takeAt(index) def add_channels(self): channels = self.channel_dialog.channels