Unsolved qkeyevent ctrl+c
-
how to catch ctrl+c/or other keys event press or release for qkeyevent or other method?
-
Hi
In a widget or Application wide ?
You can use
http://doc.qt.io/qt-5/qshortcut.html#details
For app global "hotkeys" -
@mrjj
in widget mode -
@s002wjh
You mean inside a widget when it has keyboard focus ?
You can always make a custom widget and override
keyPress.Can you explain the use case ?
Its a bit vague what you are trying to do and there are multiple ways with keys depending
on what you need it for. -
yes in my widget, i have zoom in function for my graph. I would like use ctrl+key to reset the display, so its max zoom out.
as i understand this require something like this
if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers().testFlag(Qt::ControlModifier)){
...
} -
@s002wjh
Hi
You can use the shortcut for fast way or simply override the
mousePress virtual function and check there for your custom widget.
You might need to set Focus Policy for it to accept keys. -
i like to know if this syntax is correct, hard to find the example.
if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers()==Qt::ControlModifier){
...
} -
Hi
Yes it works :)
class MainWindow : public QMainWindow { Q_OBJECT ..... protected: virtual void keyPressEvent(QKeyEvent* keyEvent) override { if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers() == Qt::ControlModifier) { qDebug() << "CTRL +c"; } }
-
@mrjj
hmm i guess i must done something wrong. i gotta double check my code. -
@s002wjh
Hi
Make sure to use the override directive so it warns you if
its not really overriding anything.do you have compiler error or in what way dont work ?
Did you do this in a custom widget ?
You might need to allow focus then. Default its off.
Try set to Click focus. then click on your widget and press ctrl+c