Results 1 to 8 of 8

Thread: keyevent/zoom

  1. #1
    Join Date
    Jan 2009
    Posts
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default keyevent/zoom

    hi,
    i have written code in keypressevent like below
    Qt Code:
    1. void GLWidget::KeyPressEvent(QKeyEvent *event)
    2. {
    3. switch(event->key())
    4. {
    5. case Qt::Key_Home :
    6.  
    7. sBoundingBox.fMinX=-180;
    8. sBoundingBox.fMinY=-90;
    9. sBoundingBox.fMaxX=+180;
    10. sBoundingBox.fMaxY=+90;
    11.  
    12. break;
    13. case Qt::Key_Plus :
    14.  
    15. sBoundingBox.fMinX += 1000.0;
    16. sBoundingBox.fMaxX -= 1000.0;
    17. sBoundingBox.fMinY += 1000.0;
    18. sBoundingBox.fMaxY -= 1000.0;
    19.  
    20. break;
    21. case Qt::Key_Minus :
    22. sBoundingBox.fMinX -= 1000.0;
    23. sBoundingBox.fMaxX += 1000.0;
    24. sBoundingBox.fMinY -= 1000.0;
    25. sBoundingBox.fMaxY += 1000.0;
    26.  
    27. break;
    28. }
    29. glMatrixMode (GL_PROJECTION);
    30. glLoadIdentity ();
    31.  
    32. glOrtho(sBoundingBox.fMinX, sBoundingBox.fMaxX,sBoundingBox.fMinY,sBoundingBox.fMaxY,-1,1);
    33. glMatrixMode(GL_MODELVIEW);
    34. //glIdleFunc(paintGL);
    35. paintGL();
    36. }
    To copy to clipboard, switch view to plain text mode 
    but program is not enterint at all into this fuction
    can anyone help me?
    thanks and regards
    k. bhogasena reddy
    Last edited by jpn; 23rd January 2009 at 12:13. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: keyevent/zoom

    Perhaps your GL widget doens't have keyboard focus.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2009
    Posts
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: keyevent/zoom

    i have setfocuspolicy(strongfocus) in qglwidget constructor

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: keyevent/zoom

    There seems to be a typo in the function name. It's keyPressEvent, not KeyPressEvent.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2009
    Posts
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: keyevent/zoom

    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.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: keyevent/zoom

    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().
    J-P Nurmi

  7. #7
    Join Date
    Jan 2009
    Posts
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: keyevent/zoom

    in setFocus(Qt::FocusReason) what i have to put for "reason"

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: keyevent/zoom

    There's an overload (a slot) provided for convenience that takes no parameters at all. It calls setFocus(Qt::OtherFocusReason).
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.