How to generate an event to ESC (Escape), F1 and such keys.
-
wrote on 6 Sept 2010, 20:02 last edited by
Here is dfaure message that was posted in the other thread:
[quote] At first sight I don’t see anything wrong with the code you posted, the problem must be elsewhere. What type of widget is “this”?
One idea could it be that the Esc key closes the dialog, and that F1 triggers some help action…In fact between posting a QKeyEvent and getting a keyEventPressed, many things can happen:
- shortcut handling (if a widget accepts the ShortcutOverride event for instance; or if a QAction exists with this key)
- event filters
Please give more information. Ideally extracting a standalone testcase, that’s the easier to look at smile. [/quote]
[cleaned up formatting and deleted the other thread = Alexandra]
-
wrote on 6 Sept 2010, 20:05 last edited by
The handler from LIRC (Linux InfraRed client or something like this) is a QObject derived class.
All the other windows are QWidgets and I'm trying to receive Keypress events in them.
I'm doind a few test on monday. Now I'm in a holliday! :D
Thanks. I'll be in touch. -
wrote on 6 Sept 2010, 21:19 last edited by
Am I getting something wrong here or is your “key interpreting” object posting events to itself.
@void QCoreApplication::postEvent ( QObject * receiver, QEvent * event )@
If that is the case than I think You should check this objects keyPressEvent, maybe those specific events get accepted by this object and their propagation stops there. -
wrote on 6 Sept 2010, 21:23 last edited by
This class is something like a keyboard driver, however not to a keyboard, it is to the IR Remote Control.
It recieves the Remote Control keypress through a socket. And that code would translate the string information about the pressed key to a QT key event.
My goal is to use this class to generate key events to the entire application.Notice that I'm generating QKeyEvents and using a signal to notify any registered slot about that too.
That's an workaround, I really want to take this signal/slots approach out and keep using the QKeyEvent part only.I believe this is how I generate key events to the entire application, so the QT framework itself decides which Widget is going to receive the event.
@
void QCoreApplication::postEvent ( QObject * receiver, QEvent * event )
@Is this wrong?
Maybe we've found the mistake. -
wrote on 6 Sept 2010, 21:32 last edited by
Maybe I'm wrong!
Now I noticed the first parameter is the RECEIVER of the Event, not the GENERATOR of the event.
Have to read a little about that.
Does anyone know something about how to generate events to the entire application (letting QT decide who is going to receive the event)? -
wrote on 6 Sept 2010, 21:46 last edited by
Just a wild guess but I would try using @QApplication::postEvent(qApp, event);@ instead of @QApplication::postEvent(this, event);@ as qApp is a pointer to the object representing the current QApplication instance. But I don't relay know if that'll result in the event being passed to the active widget I don't know.
-
wrote on 6 Sept 2010, 22:10 last edited by
I'll give a shot on Monday. Maybe we are lucky this time. Will post news asap.
-
wrote on 1 Oct 2010, 23:08 last edited by
kkrzewniak: posting events to qApp will only post the event to qApp, not to the active widget ;)
If one wants to send events to the active widget, then sending them to QApplication::focusWidget() might help.
-
wrote on 2 Oct 2010, 19:51 last edited by
Great idea.
I've been trying to find some time to test the last suggestion kkrzewniak made.
I'll do it ASAP and will try this too.
It sounds like will work.Thanks very much for your help.
-
wrote on 17 Dec 2010, 16:46 last edited by
That worked.
I had to make a lot of changes to fit with this.
But now, that's all fine!Thanks so much for your help guys.