I am trying to create QTreeWidgetItems with custom context menus. I would like to have QTreeWidget and QTreeWidgetItem derived classes like the following example:

Qt Code:
  1. class QCustomTreeWidget;
  2.  
  3. class QCustomTreeItem : public QTreeWidgetItem
  4. {
  5. public:
  6. QCustomTreeItem(QCustomTreeWidget *view);
  7. QCustomTreeItem(QCustomTreeItem *parent);
  8. virtual ~QCustomTreeItem();
  9.  
  10. virtual void onContextMenu(QContextMenuEvent *event) = 0;
  11. };
  12.  
  13. class QMyPluginItem : public QCustomTreeItem
  14. {
  15. public:
  16. QMyPluginItem(QCustomTreeWidget *view);
  17. QMyPluginItem(QCustomTreeItem *parent);
  18. virtual ~QMyPluginItem();
  19.  
  20. virtual void onContextMenu(QContextMenuEvent *event)
  21. {
  22. // create the context menu
  23. QMenu* ContextMenu = new QMenu();
  24.  
  25. QAction *actCustom = new QAction("Custom Action", ContextMenu);
  26. ContextMenu->addAction(actCustom);
  27. connect(actCustom, SIGNAL(triggered(void)), this, SLOT(onCustomAction(void)));
  28.  
  29. ContextMenu->exec( event->globalPos() );
  30.  
  31. delete ContextMenu;
  32. }
  33.  
  34. private slots:
  35. void onCustomAction();
  36. };
  37.  
  38.  
  39. class QCustomTreeWidget : public QTreeWidget
  40. {
  41. Q_OBJECT
  42. public:
  43. QCustomTreeWidget(QWidget *parent = 0);
  44. virtual ~QCustomTreeWidget();
  45.  
  46. protected:
  47. virtual void contextMenuEvent(QContextMenuEvent *event)
  48. {
  49. QCustomTreeItem* selected =
  50. reinterpret_cast<QCustomTreeItem*>(currentItem());
  51.  
  52. if ( 0 != selected )
  53. selected->onContextMenu(event);
  54. };
  55. };
To copy to clipboard, switch view to plain text mode 

I know that Singals and Slots can only work on QObjects. Looking at the documentation and the Qt source, QTreeWidgetItem is not a subclass of QObject (or anything). I dislike multiple inheritance very much, but tried deriving QCustomTreeItem from both QTreeWidgetItem and QObject to add Signal and Slot functionality. I got the following warning:

Warning: Class QCustomTreeItem inherits from two QObject subclasses QTreeWidgetItem and QObject. This is not supported!
If these did not have to be customizable plugin objects, I might just bite the bullet and put a big switch block in QCustomTreeWidget::contextMenuEvent().

Is there a way make the above model work?

Thanks!