Qt::Key_Down/Qt::Key_Up problem
-
It might be that these keys are captured at an earlier stage than in the keyPressEvent handler of the widget. Try installing an event filter to find out. First, try the filter on the QTreeWidget itself. If that doesn't get you the keys, install it on the QApplication.
-
Hello,
@ void MyClass ::keyPressEvent(QKeyEvent *event)
{
if ( event->key () == Qt::Key_Delete ) {...}
if ( event->key () == Qt::Key_Down ) {...}
if ( event->key () == Qt::Key_Up ) {...}
...
}
@
what is the event?try this
@ void MyClass ::keyPressEvent(QKeyEvent *e)
{
if ( e->key () == Qt::Key_Delete ) {...}
if ( e->key () == Qt::Key_Down ) {...}
if ( e->key () == Qt::Key_Up ) {...}
...
}
@or
@ class MyClass :public QTreeWidget
{
Q_OBJECTprotected: virtual void keyPressEvent(QKeyEvent *event); };
@
and be sure to include the #include <QKeyEvent>
-
i now its a variable.
this variable in header file
@virtual void keyPressEvent(QKeyEvent *e);@
and now in cpp file
@void MyClass ::keyPressEvent(QKeyEvent *event)@
two diffrent variable name. this is my main point.[quote author="Sam" date="1364367957"]
[quote author="bhamuryen" date="1364331122"]
what is the event?
[/quote]Its just a variable/instance name it does not matter if you change from QKeyEvent *event to QKeyEvent *e.[/quote]
-
The compiler only needs to know what kind of arguments the function requires. It's unimportant for the compiler how you call them. The function declaration only needs to specify the parameter types, order and the return type
you can also use
.h
@void keyPressEvent(QKeyEvent *);@in you header file and it works as expected.
-
Ok i tried
virtual void keyPressEvent(QKeyEvent *e);void MyClass ::keyPressEvent(QKeyEvent *event)
this work fine ;) . But we want to use filter (like tihs if ( e->key () == Qt::Key_Up ) {...}) we need to add the @#include <QKeyEvent>@
[quote author="Sam" date="1364369377"]@bhamuryen
The compiler only needs to know what kind of arguments the function requires. It's unimportant for the compiler how you call them. The function declaration only needs to specify the parameter types, order and the return type
you can also use
.h
@void keyPressEvent(QKeyEvent *);@in you header file and it works as expected.[/quote]
-
Yes ofcourse you need to add QKeyEvent header to your project inorder to access the member function of the class.