Results 1 to 2 of 2

Thread: QWidgetAction: A QTreeWidget in a QMenu

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default QWidgetAction: A QTreeWidget in a QMenu

    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 

  2. #2
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: QWidgetAction: A QTreeWidget in a QMenu

    I found this answer but it doesnt seem to work for a QTreeView/QTreeWidget... any ideas?

    http://lists.trolltech.com/qt-intere...ad00463-0.html

    Qt Code:
    1. void MyButton::mouseReleaseEvent(QMouseEvent *event)
    2. {
    3. // this one triggers the action and untoggles the button
    4. QToolButton::mouseReleaseEvent(event);
    5. // this one forwards the event to the parent
    6. QWidget::mouseReleaseEvent(event);
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Filling QTreeWidget / Using QTreeView
    By stefanborries in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2009, 15:25
  2. QMenu popup: how close when clicked outside
    By powermax in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2009, 03:18
  3. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  4. how to popup and close a QMenu
    By Placido Currò in forum Qt Programming
    Replies: 15
    Last Post: 14th May 2007, 16:41
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.