Keyboard shortcuts for QWebEngineView navigation
-
I have tried QKeySequence, QAction and QKeyEvent among other things and I can't get it to work. Here is the code.
Hi @ospf,
There are 2 ways to do it:- Using a QMenu and adding QAction to it using addAction and then setShortcut to it. I see you have already tried it but it works. The prerequisite is it needs a
QMenu
.
For Eg. Check this Browser example especially this class and browse tosetupMenu()
method - Use QShortcut and connect its
activated
signal to a slot which will get executed on trigger.
Eg.
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+r"), this); QObject::connect(shortcut, SIGNAL(activated()), view, SLOT(reload())); //view = QWebEngineView and reload() = its slot.
Edit: added example link.
- Using a QMenu and adding QAction to it using addAction and then setShortcut to it. I see you have already tried it but it works. The prerequisite is it needs a
-
Great thanks, how do I add it to my code? When I try to add the QShortcut answer to the main function I get "invalid use of 'this' in a non-member function".