Results 1 to 3 of 3

Thread: QKeyEvent

  1. #1
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QKeyEvent

    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 :

    Qt Code:
    1. void myview::keyPressEvent(QKeyEvent *e){
    2. switch(e->key()){
    3. case Qt::Key_Left :
    4. graphicsView->scale(1.2,1.2);
    5. break;
    6. case Qt::Key_Down :
    7. graphicsView->scale(1/1.2,1/1.2);
    8. break;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by jpn; 10th April 2008 at 14:54. Reason: missing [code] tags

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QKeyEvent

    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:
    Qt Code:
    1. ...
    2. MyWindow::keyPressEvent(QKeyEvent* event)
    3. {
    4. QString keyText = event->text().toUpper();
    5. if(keyText=="I")
    6. {
    7. emit vShowViewWidget();
    8. }
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    I will try to write some example code to check keyPressEvent for the view.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QKeyEvent

    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 !!!

Similar Threads

  1. QKeyEvent
    By sonuani in forum Newbie
    Replies: 8
    Last Post: 25th February 2008, 07:38
  2. what's mean of the member of QKeyEvent
    By sunote in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 21:25
  3. QKeyEvent questions
    By bglidden in forum Qt Programming
    Replies: 1
    Last Post: 3rd October 2006, 06:29
  4. Posting a QKeyEvent to a QLineEdit
    By cocheci in forum Qt Programming
    Replies: 14
    Last Post: 5th June 2006, 14:54

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.