PDA

View Full Version : keyevent/zoom



bhogasena
23rd January 2009, 13:11
hi,
i have written code in keypressevent like below

void GLWidget::KeyPressEvent(QKeyEvent *event)
{
switch(event->key())
{
case Qt::Key_Home :

sBoundingBox.fMinX=-180;
sBoundingBox.fMinY=-90;
sBoundingBox.fMaxX=+180;
sBoundingBox.fMaxY=+90;

break;
case Qt::Key_Plus :

sBoundingBox.fMinX += 1000.0;
sBoundingBox.fMaxX -= 1000.0;
sBoundingBox.fMinY += 1000.0;
sBoundingBox.fMaxY -= 1000.0;

break;
case Qt::Key_Minus :
sBoundingBox.fMinX -= 1000.0;
sBoundingBox.fMaxX += 1000.0;
sBoundingBox.fMinY -= 1000.0;
sBoundingBox.fMaxY += 1000.0;

break;
}
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();

glOrtho(sBoundingBox.fMinX, sBoundingBox.fMaxX,sBoundingBox.fMinY,sBoundingBox .fMaxY,-1,1);
glMatrixMode(GL_MODELVIEW);
//glIdleFunc(paintGL);
paintGL();
}
but program is not enterint at all into this fuction
can anyone help me?
thanks and regards
k. bhogasena reddy

jpn
23rd January 2009, 13:14
Perhaps your GL widget doens't have keyboard focus.

bhogasena
23rd January 2009, 13:36
i have setfocuspolicy(strongfocus) in qglwidget constructor

jpn
23rd January 2009, 13:48
There seems to be a typo in the function name. It's keyPressEvent, not KeyPressEvent.

bhogasena
23rd January 2009, 14:29
eventhogh i have changed it to keyPressEvent it's not working
could you please help me in this regard so that i'll be thankful to you.

jpn
23rd January 2009, 14:32
So does it have focus or not? Setting a focus policy doesn't mean it actually has focus. You can set the focus with QWidget::setFocus() and you can get the currently focused widget with QApplication::focusWidget().

bhogasena
23rd January 2009, 14:51
in setFocus(Qt::FocusReason) what i have to put for "reason"

jpn
23rd January 2009, 15:28
There's an overload (a slot) provided for convenience that takes no parameters at all. It calls setFocus(Qt::OtherFocusReason).