Hi,
I see this message every time I show a menu inside a QToolButton in a QToolBar:
QToolButton: Menu in setMenu() overriding actions set in addAction!

What I want to do is a button which can change function (to switch the selection mode of a QGraphicsView).
In the code there is tool button for "scroll" mode and a tool button for "select" mode wich contains a menu with "select intersected" and "select contained".
All the 3 actions are mutually exclusive.
The code works very well and does exactly what I needed, but I don't like that message which is shown each time I click to show the menu (not when I click an action).

Here is the code used to create them:
Qt Code:
  1. // Create the toolbar
  2. m_selectionToolbar = new QToolBar;
  3. m_selectionToolbar->setOrientation(Qt::Horizontal);
  4. m_selectionToolbar->setWindowTitle(tr("Selection toolbar", "Toolbar"));
  5.  
  6. // Group mutually exclusive actions
  7. QActionGroup *actionGroup = new QActionGroup(this);
  8.  
  9. // Use mouse to scroll the view
  10. m_actionScrollHand = new QAction(actionGroup);
  11. m_actionScrollHand->setCheckable(true);
  12. m_actionScrollHand->setText(tr("&Scroll", "Action"));
  13. m_actionScrollHand->setStatusTip(tr("Drag to scroll the draw area", "Action"));
  14. m_actionScrollHand->setIcon(QIcon(":/images/move.png"));
  15. connect(m_actionScrollHand, SIGNAL(triggered()), this, SLOT(actionScrollHand_triggered()));
  16. m_selectionToolbar->addAction(m_actionScrollHand);
  17.  
  18. // Use mouse to select items
  19. m_selectionModeMenu = new QMenu;
  20.  
  21. m_actionIntersectsItem = new QAction(actionGroup);
  22. m_actionIntersectsItem->setCheckable(true);
  23. m_actionIntersectsItem->setText(tr("Select &intersected", "Action"));
  24. m_actionIntersectsItem->setStatusTip(tr("Drag to select items intersected by the rubber band", "Action"));
  25. m_actionIntersectsItem->setIcon(QIcon(":/images/selectintersected.png"));
  26. connect(m_actionIntersectsItem, SIGNAL(triggered()), this, SLOT(actionIntersectsItem_triggered()));
  27. m_selectionModeMenu->addAction(m_actionIntersectsItem);
  28.  
  29. m_actionContainsItem = new QAction(actionGroup);
  30. m_actionContainsItem->setCheckable(true);
  31. m_actionContainsItem->setText(tr("Select &contained", "Action"));
  32. m_actionContainsItem->setStatusTip(tr("Drag to select items contained by the rubber band", "Action"));
  33. m_actionContainsItem->setIcon(QIcon(":/images/selectcontained.png"));
  34. connect(m_actionContainsItem, SIGNAL(triggered()), this, SLOT(actionContainsItem_triggered()));
  35. m_selectionModeMenu->addAction(m_actionContainsItem);
  36.  
  37. m_selectionModeButton = new QToolButton;
  38. m_selectionModeButton->setPopupMode(QToolButton::MenuButtonPopup);
  39. m_selectionModeButton->setMenu(m_selectionModeMenu);
  40.  
  41. // Set default action
  42. m_selectionModeButton->setDefaultAction(m_actionIntersectsItem);
  43. m_actionIntersectsItem->setChecked(true);
  44.  
  45. m_selectionToolbar->addWidget(m_selectionModeButton);
To copy to clipboard, switch view to plain text mode 

And here are the slots:
Qt Code:
  1. void GraphicsDrawView::actionScrollHand_triggered()
  2. {
  3. m_drawView->setDragMode(QGraphicsView::ScrollHandDrag);
  4. }
  5.  
  6. void GraphicsDrawView::actionIntersectsItem_triggered()
  7. {
  8. m_drawView->setDragMode(QGraphicsView::RubberBandDrag);
  9. m_drawView->setRubberBandSelectionMode(Qt::IntersectsItemShape);
  10. m_selectionModeButton->setDefaultAction(m_actionIntersectsItem);
  11. }
  12.  
  13. void GraphicsDrawView::actionContainsItem_triggered()
  14. {
  15. m_drawView->setDragMode(QGraphicsView::RubberBandDrag);
  16. m_drawView->setRubberBandSelectionMode(Qt::ContainsItemShape);
  17. m_selectionModeButton->setDefaultAction(m_actionContainsItem);
  18. }
To copy to clipboard, switch view to plain text mode 

Here instead are the variables (which are in the header):
Qt Code:
  1. QPointer< DrawView > m_drawView; // Inherits QGraphicsView
  2. QPointer< QToolBar > m_selectionToolbar;
  3. QAction *m_actionScrollHand;
  4. QAction *m_actionIntersectsItem;
  5. QAction *m_actionContainsItem;
  6. QToolButton *m_selectionModeButton;
  7. QMenu *m_selectionModeMenu;
To copy to clipboard, switch view to plain text mode