[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Strange behaviour of keyPressEvent and KActions with shortcut
From: "Albert 'TSDgeos' Astals Cid" <tsdgeos () terra ! es>
Date: 2003-07-20 22:00:42
[Download RAW message or body]
If it define a KAction with Left_arrow as shortcut, the widget's keyPressEvent
function never receives an event for the press of Left_arrow. This is a
strange behaviour as keyPressEvent should receive all the key events that
happen in that widget (i think that is reasonable).
keyReleaseEvent does receive the release event.
Some code illustrating that.
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <kaction.h>
#include <kmainwindow.h>
class MyWidget : public KMainWindow
{
public:
MyWidget();
protected:
virtual void keyPressEvent( QKeyEvent *event );
virtual void keyReleaseEvent( QKeyEvent *event );
private:
KAction *mAction;
};
MyWidget::MyWidget() : KMainWindow(0, 0, WType_Modal)
{
mAction = new KAction(i18n("Move Left"), Qt::Key_Left, 0, 0,
actionCollection(), "move_left");
resize(500, 500);
show();
}
void MyWidget::keyPressEvent(QKeyEvent* event)
{
setCaption("Key Pressed");
KKey key(event);
if (mAction->shortcut().contains(key))
{
setCaption("Left Key Pressed");
}
else event->ignore();
}
void MyWidget::keyReleaseEvent(QKeyEvent* event)
{
setCaption("Key Released");
KKey key(event);
if (mAction->shortcut().contains(key))
{
setCaption("Left Key Released");
}
else event->ignore();
}
int main(int argc, char *argv[])
{
KAboutData *data = new KAboutData("a", "", "", "", 1, "", 0, 0, "");
KCmdLineArgs::init(argc, argv, data);
KApplication a(argc, argv);
MyWidget *x = new MyWidget();
a.setMainWidget(x);
return a.exec();
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic