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. QAction Qt::Key_Return shortcut is triggered by user entering values in GUI
Forum Updated to NodeBB v4.3 + New Features

QAction Qt::Key_Return shortcut is triggered by user entering values in GUI

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k Views 1 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Dear all,
    I have an issue with associating a shotcut to a QAction. After mapping Enter to an action like this: @myAction->setShortcut(Qt::Key_Return);@ This action is triggered when I type a value in a QSpinBox and then press enter. I was expecting the spinbox to "accept" the event, so it's not caught by the mainwindow.
    I've seen that I can add a context to my shortcut, I tried all values but this does not solve my issue.

    Thanks a lot for your help.

    EDIT: found someone with the same question but no answer :( http://lists.qt.nokia.com/pipermail/qt-interest/2009-July/010340.html

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlekseyOk
      wrote on last edited by
      #2

      Hi. Try next in you MainWindow:

      @
      QAction* action1 = new QAction(this);
      action1->setShortcut(QKeySequence(tr("Alt+F"))); // Or whatever you need
      addAction(action1);
      connect(action1, SIGNAL(triggered()), this, SLOT(action1Triggered()));
      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        I don't understand why your code would solve my issue? This is more or less what I'm already doing.
        Could you explain it? Thanks a lot

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AlekseyOk
          wrote on last edited by
          #4

          ok.

          To process key-strokes in QLineeEdit you should override virtual function
          @
          virtual void keyReleaseEvent(QKeyEvent *event)
          // or
          virtual void keyPressedEvent(QKeyEvent *event)
          @

          1. my example adds global shortcut to main window
          2. you can try to install an event filter to QLineEdit - call
            @
            you_QLineEditObjPtr->installEventFilter(aMainWindowObjPtr);
            @
          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            I would like to avoid subclassing all the standard widgets that do not accept and consume the Enter pressed event.

            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