QAction shortcuts in QML
-
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
-
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!
-
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 :) -
It seems QAction is something specific for QtWidgets.
A solution is to override @void keyPressEvent(QKeyEvent* event);@