Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QAction shortcuts in QML
QtWS25 Last Chance

QAction shortcuts in QML

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.7k Views
  • 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.
  • B Offline
    B Offline
    Babalas
    wrote on last edited by
    #1

    I have an application that has QQuickView set as the central widget of QMainWindow through a proxy class QWindowContainer (lost where I found this class). This all seems to work, except QAction shortcuts, if the focus is on QQuickView. For instances I want to be able to hit F5 to do a refresh in my application. I have this bound up:
    @ _refreshPresentationAction = new QAction(QIcon(":/refresh.png"), tr("&Refresh"), this);
    _refreshPresentationAction->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_F5));
    _refreshPresentationAction->setStatusTip(tr("Refresh the presentation"));
    connect(_refreshPresentationAction, SIGNAL(triggered()), this, SLOT(_refreshPresentation()));@

    If the focus is on QMainWindow then it works, but if the focus is in my customised QQuickItem nothing happens. I've overrided keyPressEvent and do get the F5 keyEvent coming through, but I don't know where to send it from there?

    Cheers for any help

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xarxer
      wrote on last edited by
      #2

      I'm also interested in this. I have a class which derives from QQuickView and I'm trying to use a simple QAction in it like this
      @
      Client::Client(QWindow* parent) : QQuickView(parent)
      {
      //[...]
      quitAction = new QAction(this);
      quitAction->setShortcut(QKeySequence(Qt::Key_F5));

      connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
      //[...]
      

      }
      @

      However, the QQuickView doesn't seem to react when I press F5. I'd be happy to post more code if needed. Any help greatly appreciated!

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tzander
        wrote on last edited by
        #3

        Would you have keyboard focus set to true somewhere? Or a FocusScope in your app?
        Likely you eat the events in your qml app, therefore the view doesn't get them.
        Go to the FocusScope qml widget and read up on all things keyboard-focus :)

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xarxer
          wrote on last edited by
          #4

          It seems QAction is something specific for QtWidgets.
          A solution is to override @void keyPressEvent(QKeyEvent* 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