PDA

View Full Version : QKeyEvent



peace_comp
9th April 2008, 23:58
Hi..
I would Like to use the keybord to generate events on my application ..but I still don't know how to use the QKeyEvent..
The idea is To zoom (translate ... ) on a View ( QGraphicsView) everytime we press on the Key (Up,Down,Right,Left) ..So I tried to create a methode for that Using QkeyEvent :


void myview::keyPressEvent(QKeyEvent *e){
switch(e->key()){
case Qt::Key_Left :
graphicsView->scale(1.2,1.2);
break;
case Qt::Key_Down :
graphicsView->scale(1/1.2,1/1.2);
break;
}
}

but it dosnt work ( nothing happens when I press left or right Key) ??
Should I connect that methode to a specific SIGNAL ? if it the case wht signal should I use ?!!
Please if someOne have a idea ..
thanks

maverick_pol
10th April 2008, 00:07
Hi,

I am using the GraphicsView framework in my apps.
When the user clicks "I" some widget in the QGraphisView should be shown/hidden.
I have implemented my QMainWindow::keyPressEvent(QKeyEvent* key)
and in that method I emit signal connected with QGraphicsView parent slots.
It works for me, but still it should work with yourwidget::keyPressEvent(...)
Some sample code:


...
MyWindow::keyPressEvent(QKeyEvent* event)
{
QString keyText = event->text().toUpper();
if(keyText=="I")
{
emit vShowViewWidget();
}
...
}

I will try to write some example code to check keyPressEvent for the view.

Kacper

peace_comp
10th April 2008, 13:13
hi..
thanks..
The problem I had was within the declaration ..
i tried ur code using the event->text() .. and it worked .. i guess The problem was on the Qt::Key_Up ..
i must now find another way to use the key up..
thanks !!!