I'm trying to get a QTreeWidget into the submenu of a context menu. (This is to allow users to selected alternate versions of the thing they're right clicking on).

I created a custom QWidgetAction but for some reason the widget doesnt disappear when the action is triggered. Any ideas on why this isnt working??

Qt Code:
  1. class QdVersionListAction(QtGui.QWidgetAction):
  2. def __init__(self, path, parent=None):
  3. QtGui.QWidgetAction.__init__(self, parent)
  4. self.path = path
  5. self.new_version = ""
  6.  
  7. def createWidget(self, parent):
  8. widget = QdVersionTree(self.path, parent)
  9. widget.setMinimumSize(450, 100)
  10. self.connect(widget, SIGNAL("versionSelected(QString)"), self.versionAccepted)
  11. self.activate(QtGui.QAction.Trigger)
  12. return widget
  13.  
  14. def versionAccepted(self, path):
  15. self.new_version = path
  16. # this works, the triggered signal is emitted and all
  17. self.activate(QtGui.QAction.Trigger)
  18.  
  19. # What else can I do here????
  20. self.emit(SIGNAL("changed()"))
  21. self.toggle()
  22. print 'version accepted', path
  23.  
  24. class QdVersionTree(QtGui.QTreeWidget):
  25. def __init__(self, path, parent=None):
  26. QtGui.QTreeWidget.__init__(self, parent)
  27. self.setAllColumnsShowFocus(True)
  28.  
  29. attributes = ["version", "name", "creator", "description"]
  30. self.setHeaderLabels(atributes)
  31. self.setFrameStyle(QtGui.QFrame.NoFrame)
  32.  
  33. versions = [1, 2, 3, 4, 5, 6]
  34. for version in versions:
  35. columns = []
  36. for attribute in attributes:
  37. columns.append(attribute)
  38.  
  39. item = QdVersionTreeItem(self, columns)
  40. self.addTopLevelItem(item)
  41.  
  42. self.connect(self, SIGNAL("itemActivated(QTreeWidgetItem *, int)"),
  43. self.itemActivated)
  44.  
  45. def itemActivated(self, item, column):
  46. self.emit(SIGNAL("versionSelected(QString)"), "foo")
To copy to clipboard, switch view to plain text mode