From 4bdbc5b259d6f8f1e4018ad1d724dac06af32d15 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 9 Sep 2016 12:51:12 +0800 Subject: [PATCH] applets: use a different workaround to disable editing True to itself, Qt did not miss the opportunity to trash widgets inside QTreeWidgetItems when they are moved by drag-and-drop. Problem known for more than 6 years and still not fixed as of Qt 5.7. --- artiq/dashboard/applets_ccb.py | 5 ++--- artiq/gui/applets.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/artiq/dashboard/applets_ccb.py b/artiq/dashboard/applets_ccb.py index 963855a6b..0f2c50fc8 100644 --- a/artiq/dashboard/applets_ccb.py +++ b/artiq/dashboard/applets_ccb.py @@ -76,8 +76,7 @@ class AppletsCCBDock(applets.AppletsDock): self.ccbp_group_action.setEnabled(False) else: self.ccbp_group_action.setEnabled(True) - print(item, item.ty) - ccbp = self.table.itemWidget(item, 1).text() + ccbp = item.text(1) if ccbp == "": self.ccbp_group_none.setChecked(True) else: @@ -89,7 +88,7 @@ class AppletsCCBDock(applets.AppletsDock): item = self.table.selectedItems()[0] if item.ty == "applet": item = item.parent() - self.table.itemWidget(item, 1).setText(ccbp) + item.setText(1, ccbp) def get_ccpb_global(self): if self.ccbp_global_ignore.isChecked(): diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index 66c011bea..91636d601 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -376,6 +376,14 @@ class AppletsDock(QtWidgets.QDockWidget): self.table.itemChanged.connect(self.item_changed) + # HACK + self.table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) + self.table.itemDoubleClicked.connect(self.open_editor) + + def open_editor(self, item, column): + if column != 1 or item.ty != "group": + self.table.editItem(item, column) + def get_spec(self, item): if item.applet_spec_ty == "command": return {"ty": "command", "command": item.text(1)} @@ -505,7 +513,7 @@ class AppletsDock(QtWidgets.QDockWidget): def new_group(self, name=None, attr="", parent=None): if name is None: name = self.get_untitled() - item = QtWidgets.QTreeWidgetItem([name]) + item = QtWidgets.QTreeWidgetItem([name, attr]) item.ty = "group" item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | @@ -520,9 +528,6 @@ class AppletsDock(QtWidgets.QDockWidget): self.table.addTopLevelItem(item) else: parent.addChild(item) - # HACK: make the cell non-editable. Qt doesn't even provide - # a clean API for such a basic feature. - self.table.setItemWidget(item, 1, QtWidgets.QLabel(attr)) return item def new_with_parent(self, cb, **kwargs): @@ -605,7 +610,7 @@ class AppletsDock(QtWidgets.QDockWidget): state.append(("applet", uid, enabled, name, spec, geometry)) elif cwi.ty == "group": name = cwi.text(0) - attr = self.table.itemWidget(cwi, 1).text() + attr = cwi.text(1) expanded = cwi.isExpanded() state_child = self.save_state_item(cwi) state.append(("group", name, attr, expanded, state_child))