View Full Version : Overwrite QKeyEvent
haldrik
26th October 2008, 01:38
Hello everibody
I need get how to overwrite the QKeyEvent, to get the tab behaviour with the enter-return key.
JimDaniel
26th October 2008, 03:01
You could more easily override a QWidget and reimplement its keyPressEvent() or keyReleaseEvent(), catch the Enter Key, then do whatever you want...
#ifndef KEY_WIDGET_H
#define KEY_WIDGET_H
#include <QWidget>
class KeyWidget : public QWidget
{
public:
KeyWidget();
virtual ~KeyWidget();
protected:
void keyReleaseEvent(QKeyEvent * ke);
}
#endif //KEY_WIDGET_H
#include "keywidget.h"
KeyWidget::KeyWidget() {}
KeyWidget::~KeyWidget() {}
void keyReleaseEvent(QKeyEvent * ke)
{
if(ke->key() == Qt::Key_Return)
{
//do something...
}
}
haldrik
8th November 2008, 19:27
Ok, but how I can use this reimplemented QWidget's function on a desired widget?
caduel
8th November 2008, 19:43
either
* derive from the widget and override the method there
* or install an event filter QObject::installEventFilter()
(this is the way to go if you need to watch many widgets and esp. if you have to watch widgets that you did/can not implement yourself.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.