Home > Mobile >  For custom controls the custom shortcuts
For custom controls the custom shortcuts

Time:10-03

Requirement description:
Control is inherits QWidget, through the draw button, now need to increase the shortcut key function (user customizable)
Said the first mouse operations:
The mouse to press the peace talks, will happen one or two operations, it is assumed that as A and B operation (according to the given mode)
1) the mouse press have A operational
2) the mouse to press A operation, B
operation in the aftermath of the delay3) the press in operation, the mouse pop-up happened B operation

I once considered implementation ways, here to talk about their problems:
(1) in accordance with the Qt button is implemented (after the actual test)
The problem: can the normal access to the shortcut key event, but not achieve the 3) that the point, when the shortcut keys to cancel I can't get the message to invoke the operation
B
(2) the reload button presses the button up event and
The problem: because shortcuts are user defined, unpredictable, key number and value judgments difficulties,
Also not clear how to realize the capture range, scope of official shortcut keys can be set to grab: for example, the application level, the level of window, level of parts such as

(3) to carry a QAction custom controls, only need to connect the QAction signal
The problem: in accordance with (1) the problems in the

Now very embarrassed subsidence here
Want to ask next everybody have a great god solve the appeal three ways of any kind of problems existing in the method?
Or provide a new solution, very grateful,

Here heavily for!!!!!!!!!!
Oh, no, redistribution of solving

CodePudding user response:

PushButton binding shortcuts, can trigger the Button pressed and released the signal,

CodePudding user response:

Your own picture button, need to customize the signals, if your button is not from QPushButton or QAbstractButton inheritance, then you have to from QWidget inheritance, you then need to rewrite some of the key related to the event. When key events occur the position in your picture button emit conceal you click signal of the custom

CodePudding user response:

1/f, bow quoted water response:
PushButton binding shortcuts, can trigger the Button pressed and released signals,


refer to the second floor donwmufromdying response:
your own picture button, need to customize the signals, if your button is not from QPushButton or QAbstractButton inheritance, then you have to from QWidget inheritance, you then need to rewrite some of the key related to the event. When a key event occurs when the position of the button in your painting emit conceal your custom click signal


It's not the problem, the mouse button is the mouse has been achieved,
I want to use the shortcut keys for the same effect, namely:
Shortcut keys pressed and shortcuts to release,
1) referring to the implementation of QAbstractButton shortcuts, can only capture to shortcut key press, loosen the button can't judge
2) the reload button, one is the shortcut key users set (key value and quantity) is a little bad compare with buttons; Grab the scope of the also don't know how

CodePudding user response:

PushButton binding shortcut key, press the shortcut key trigger pressed, lift the shortcut key trigger released, can not meet?

Other QAction QShorcut, because qapplication source is inside when pressed to distribute shortcuts, so usually shortcuts exist only when press the trigger signal, when lift, there is no corresponding shortcut fetching interface,

Moreover, the shortcut key to lift trigger needs a special operation, estimates that need to implement a shortcut key mechanism, do not use Qt's own,
Don't want to use Qt shortcut keys, so the need to monitor the release of the keyboard events, and then to form a shortcut key events is a state machine,

CodePudding user response:

4th floor bow quoted water response:
PushButton binding shortcuts, press the shortcut key trigger pressed, lift the shortcut key trigger released, can not meet?

Can you more details about this?

I learned that PushButton it is only in the shortcut key press that button to trigger, shortcut also support long according to repeat,
By rights I can use a timer to determine whether to cancel the long press, but very embarrassed, real-time system requirements, more than a few hundred milliseconds of delay is a bit difficult to accept

CodePudding user response:

Well, QAbstractButton source is indeed a shortcut key press the trigger, long press the trigger, there is no lift shortcut key signal,

The only inheritance QGUIApplication, rewrite the notify method, and then add a shortcut to the lift,

See the Qt source, you have ideas,
 
The switch (e - & gt; The type ()) {
Case QEvent: : KeyPress: {
QKeyEvent * keyEvent=static_cast & lt; QKeyEvent * & gt; (e);
Const int key=keyEvent - & gt; The key ();
//the When a key press is received which is not what then it needs to
//be manually sent as a shortcut override the event to ensure that any
//matching shortcut is triggered first. This enables emulation/playback
//of recorded events to still have the same effect.
if (! E - & gt; What () & amp; & The receiver - & gt; IsWidgetType ()) {
If (qt_sendShortcutOverrideEvent (qobject_cast & lt; QWidget * & gt; (receiver), keyEvent - & gt; Timestamp (),
The key, keyEvent - & gt; Modifiers (), keyEvent - & gt; The text (),
KeyEvent - & gt; IsAutoRepeat (), keyEvent - & gt; The count ()))
return true;
}
Qt_in_tab_key_event=(key==Qt: : Key_Backtab
| | key==Qt: : Key_Tab
| | key==Qt: : Key_Left
| | key==Qt: : Key_Up
| | key==Qt: : Key_Right
| | key==Qt: : Key_Down);
}
Default:
break;
}

CodePudding user response:

6th floor bow quoted water response:
well, QAbstractButton source is indeed a shortcut key press the trigger, long press the trigger, there is no lift shortcut key signal,

The only inheritance QGUIApplication, rewrite the notify method, and then add a shortcut to the lift,

See the Qt source, you have ideas,
 
The switch (e - & gt; The type ()) {
Case QEvent: : KeyPress: {
QKeyEvent * keyEvent=static_cast & lt; QKeyEvent * & gt; (e);
Const int key=keyEvent - & gt; The key ();
//the When a key press is received which is not what then it needs to
//be manually sent as a shortcut override the event to ensure that any
//matching shortcut is triggered first. This enables emulation/playback
//of recorded events to still have the same effect.
if (! E - & gt; What () & amp; & The receiver - & gt; IsWidgetType ()) {
If (qt_sendShortcutOverrideEvent (qobject_cast & lt; QWidget * & gt; (receiver), keyEvent - & gt; Timestamp (),
The key, keyEvent - & gt; Modifiers (), keyEvent - & gt; The text (),
KeyEvent - & gt; IsAutoRepeat (), keyEvent - & gt; The count ()))
return true;
}
Qt_in_tab_key_event=(key==Qt: : Key_Backtab
| | key==Qt: : Key_Tab
| | key==Qt: : Key_Left
| | key==Qt: : Key_Up
| | key==Qt: : Key_Right
| | key==Qt: : Key_Down);
}
Default:
break;
}

Ok, thank you very much,
  •  Tags:  
  • Qt
  • Related