Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No context menu in QWidget when pressing the menu-Key?
Forum Updated to NodeBB v4.3 + New Features

No context menu in QWidget when pressing the menu-Key?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wurgl
    wrote on last edited by A Former User
    #1

    Solved!

    need to call QWidget::setFocusPolicy().

    With menu Key, I mean this one:
    https://en.wikipedia.org/wiki/Menu_key

    I 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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! As you marked the thread as solved, may I ask what the your solution was?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        @Wieland At the top of the post, @Wurgl mentions adding somewhere a call to setFocusPolicy.

        @Wurgl, on a side note, you have a memory leak in your application. You should either keep d on the stack or delete it after you return from exec.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        ? 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          @Wieland At the top of the post, @Wurgl mentions adding somewhere a call to setFocusPolicy.

          @Wurgl, on a side note, you have a memory leak in your application. You should either keep d on the stack or delete it after you return from exec.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @SGaist Oh, right. I think I need glasses :))

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved