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.
This commit is contained in:
Sebastien Bourdeauducq 2016-09-09 12:51:12 +08:00
parent 6144839beb
commit 4bdbc5b259
2 changed files with 12 additions and 8 deletions

View File

@ -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():

View File

@ -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))