Thank you marcel for your detailed explanation, it was very helpful!
I could solve the problem!
Although your solution did not work (changing the position of setDefaultAction() did not change anything, moreover I still needed to call it in the slots at user request), this sentence made me understand the problem:

Originally Posted by
marcel
As you can see later in the function, if you set any menu with setMenu, then this menu will get displayed, rendering any actions that you add via addAction useless( they will be overwritten by the action you will select in the menu ).
As you told, every QWidget has a list of actions, so adding a QMenu to it was not necessary and went to override the internal list of actions. The list was not empty because of setDefaultAction() which added the action to the list of widget actions in some way.
The solutions now is very simple: instead of adding the actions to a QMenu and setting the menu to the QToolButton, you need only to add the actions directly to the QToolButton!
In this way the menu is auto-generated with the list of the QWidget actions.
Here is the code:
m_selectionModeButton
->setPopupMode
(QToolButton::MenuButtonPopup);
m_selectionModeButton->addAction(m_actionIntersectsItem); // New line!
m_selectionModeButton->addAction(m_actionContainsItem); // New line!
m_selectionModeButton->setDefaultAction(m_actionIntersectsItem);
// Removed lines
//m_selectionModeMenu = new QMenu;
//m_selectionModeMenu->addAction(m_actionIntersectsItem);
//m_selectionModeMenu->addAction(m_actionContainsItem);
//m_selectionModeButton->setMenu(m_selectionModeMenu);
m_selectionModeButton = new QToolButton;
m_selectionModeButton->setPopupMode(QToolButton::MenuButtonPopup);
m_selectionModeButton->addAction(m_actionIntersectsItem); // New line!
m_selectionModeButton->addAction(m_actionContainsItem); // New line!
m_selectionModeButton->setDefaultAction(m_actionIntersectsItem);
// Removed lines
//m_selectionModeMenu = new QMenu;
//m_selectionModeMenu->addAction(m_actionIntersectsItem);
//m_selectionModeMenu->addAction(m_actionContainsItem);
//m_selectionModeButton->setMenu(m_selectionModeMenu);
To copy to clipboard, switch view to plain text mode
Now the code is even simpler!
I hope this solution can help someone else too in the future!
Thank you very much to every one for the help and thank you again marcel for the problem description which made me find the solution!
Bookmarks