Re: Key Press Event Handling
Re: Key Press Event Handling
You need to set a focusPolicy
Re: Key Press Event Handling
Your event handler signature is wrong.
The documentation for QObject::installEventFilter() has an example exactly for key press events.
Why not start there?
http://doc.qt.nokia.com/latest/qobje...allEventFilter
Re: Key Press Event Handling
Well then.
@pan : i added focus policy
and done somethings but thats have no effect.
i made it with QDialog base class. But with QMainWindows its not working. I'm tired.
I just open Qt Creator and create gui application, which is using QMainWindow base class.
mainwindows.cpp
Code:
#include "mainwindow.h"
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
) :{
ui->setupUi(this);
this->setWindowFlags(Qt::Dialog);
this->setFocusPolicy(Qt::NoFocus);
ui->textEdit->setFocusPolicy(Qt::StrongFocus);
ui->textEdit->installEventFilter(this);
}
{
if (obj
== ui
->textEdit
&& event
->type
()==QEvent::KeyPress) {
QKeyEvent *keyevent
= static_cast<QKeyEvent
*>
(event
);
qDebug() << "key event";
return QObject::eventFilter(obj,event
);
}
return QObject::eventFilter(obj,event
);
}
Problem is not solved but i'm tired about 2 days. I will do with QDialog class.
Thanks all...
Re: Key Press Event Handling
Quote:
Problem is not solved but i'm tired about 2 days.
I told you what the problem is!
And I gave a link to almost exactly the code you need, you only need to copy paste and introduce the changes in the handler to do the filtering based on the rules you need it.
So what is the problem?
heh... you really should read your own signature and apply some though on it...
Re: Key Press Event Handling
Ok. Punch me :)
Bro its really not working. You think, i make joke ?
Try if you didnt believe ok.
Thanks so.
I'm missing something' s.. But i cant find it yet.
Re: Key Press Event Handling
:rolleyes:
Quote:
The event filter filterObj receives events via its eventFilter() function.
not 'catch_event'.
all you had to do is COPY PASTE the example!!
Code:
//change the class name to your
{
if (event
->type
() == QEvent::KeyPress) { //and here put your own logic!!
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
qDebug("Ate key press %d", keyEvent->key());
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event
);
}
}
Re: Key Press Event Handling
Well, show me a corner. I will cry at there...
Code:
this->textEdit->installEventFilter(this);
I find where i missed up.
My goal is make a terminal program like putty.
Thanks. ;) :p