I want to pop up a not collapsed QMenu on a QWidget without user interaction. At the moment, I get the QMenu on the otherwise empty QWidget after a right click. Is there any way to invoke a contextMenuEvent(QContextMenuEvent *event) signal programmatically?
As an alternative I could add a menu to the menubar. However, this is collapsed. Would it be possible to show the menu not collapsed?
I am glad for any idea. Thanks!
Edit: Code snippet
TestMenu::TestMenu(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//remove frame from widget
this->setWindowFlags(Qt::FramelessWindowHint );
//add menu
QMenu menu(this);
QAction* firstEntry = new QAction(tr("Ask a question"), this);
connect(firstEntry, SIGNAL(triggered()), this, SIGNAL(askCollegueDialogRequested()));
menu.addAction(firstEntry);
menu.popup(this->mapToGlobal(QPoint(0,0)));
menu.activateWindow();
}
I only see the empty widget without the menu. I call the show() for the widget from another class. The problem might be that the QMenu is not really added to the widget. But I don't now how to add it without using a menubar :-(.