schooner
20th March 2014, 17:18
Hi
This is driving me nuts, so hopefully someone has the answer.
I am re-implementing QApplication to filter all mouse and keyboard events to a widget which is embedded into a tk application.
tk does not pass on focus properly and the tk app needs some crucial keystrokes forwarded, so I have to check everything
including checking which child widget is the receiver and forcing focus in some instances.
I just finished dealing with mouse clicks and went to add keystrokes
bool FilterApplication::notify( QObject *receiver, QEvent *event )
{
if(event->type() == QEvent::MouseButtonPress)
qDebug() << "Button Pressed";
if(event->type() == QEvent::KeyRelease)
qDebug() << "Key Released";
.......
}
The test for mouse events is fine, but when I try to do the same for key press / release events I get
FilterApplication.cpp: In member function ‘virtual bool FilterApplication::notify(QObject*, QEvent*)’:
FilterApplication.cpp:33:29: error: expected unqualified-id before numeric constant
FilterApplication.cpp:33:29: error: expected ‘)’ before numeric constant
make: *** [FilterApplication.o] Error 1
I can cast the event eg.
QKeyEvent *K = (QKeyEvent*)event;
if (K->key() == Qt::Key_Escape)
qDebug() << "Escape Pressed";
That works fine, except that I get 3 key codes instead of 1 for release and I am casting and testing stuff that isn't key events
Hopefully something simple, but my head is scrambled trying to find it.
Qt 4.8 on Linux
regards
This is driving me nuts, so hopefully someone has the answer.
I am re-implementing QApplication to filter all mouse and keyboard events to a widget which is embedded into a tk application.
tk does not pass on focus properly and the tk app needs some crucial keystrokes forwarded, so I have to check everything
including checking which child widget is the receiver and forcing focus in some instances.
I just finished dealing with mouse clicks and went to add keystrokes
bool FilterApplication::notify( QObject *receiver, QEvent *event )
{
if(event->type() == QEvent::MouseButtonPress)
qDebug() << "Button Pressed";
if(event->type() == QEvent::KeyRelease)
qDebug() << "Key Released";
.......
}
The test for mouse events is fine, but when I try to do the same for key press / release events I get
FilterApplication.cpp: In member function ‘virtual bool FilterApplication::notify(QObject*, QEvent*)’:
FilterApplication.cpp:33:29: error: expected unqualified-id before numeric constant
FilterApplication.cpp:33:29: error: expected ‘)’ before numeric constant
make: *** [FilterApplication.o] Error 1
I can cast the event eg.
QKeyEvent *K = (QKeyEvent*)event;
if (K->key() == Qt::Key_Escape)
qDebug() << "Escape Pressed";
That works fine, except that I get 3 key codes instead of 1 for release and I am casting and testing stuff that isn't key events
Hopefully something simple, but my head is scrambled trying to find it.
Qt 4.8 on Linux
regards