No context menu in QWidget when pressing the menu-Key?
Solved
General and Desktop
-
Solved!
need to call QWidget::setFocusPolicy().
With menu Key, I mean this one:
https://en.wikipedia.org/wiki/Menu_keyI have here a neat Linux and the context key works fine in some list & tree views, it works fine inside edit fields (QLineEdit, QTextEdit, QSpinBox, ...) but inside a simple QWidget the context menu opens just with the mouse and not with the keyboard.
#include <QApplication> #include <QDialog> #include <QAction> #include <QBoxLayout> int main(int argc, char *argv[]) { QApplication a(argc, argv); QDialog *d = new QDialog(); QVBoxLayout *l = new QVBoxLayout(d); QWidget *w = new QWidget(d); l->addWidget(w); d->resize(100, 100); w->setContextMenuPolicy(Qt::ActionsContextMenu); w->addAction(new QAction("Test", w)); d->show(); return d->exec(); }
Any hints or ideas?
-
Hi! As you marked the thread as solved, may I ask what the your solution was?
-