Results 1 to 14 of 14

Thread: i need to use Alt+Ctrl+arrow keys combination

  1. #1
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default i need to use Alt+Ctrl+arrow keys combination

    i need to use Alt+Ctrl+arrow keys on custamised QGraphicsItem, i have tried below one, not working can any one suggest me better one

    Qt Code:
    1. void CBoxViewItem::keyPressEvent(QKeyEvent* f_event) //CBoxViewItem derived from Qgraphicsitem
    2. {
    3. if(Qt::ControlModifier & Qt::AltModifier & f_event->modifiers()) // i tried this also if( (Qt::ControlModifier && Qt::AltModifier) == f_event->modifiers())
    4. {
    5. qDebug()<<"ctrl+Alt";
    6.  
    7. switch(f_event->key())
    8. {
    9. case Qt::Key_Up:
    10.  
    11. break;
    12. case Qt::Key_Down:
    13.  
    14. break;
    15. case Qt::Key_Left:
    16.  
    17. break;
    18. case Qt::Key_Right:
    19.  
    20. break;
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 4th September 2013 at 10:07. Reason: code tags

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    This should help
    Qt Code:
    1. class Widget : public QLabel
    2. {
    3. public:
    4. explicit Widget(QWidget * parent = 0)
    5. : QLabel(parent)
    6. {
    7. installEventFilter(this);
    8. }
    9. protected:
    10. bool eventFilter(QObject *, QEvent * event)
    11. {
    12. if(event->KeyPress)
    13. {
    14. QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
    15.  
    16. if(keyEvent->type() == QEvent::KeyPress)
    17. {
    18. if(keyEvent->modifiers().testFlag(Qt::AltModifier) &&
    19. keyEvent->modifiers().testFlag(Qt::ControlModifier) )
    20. {
    21. switch(keyEvent->key())
    22. {
    23. case Qt::Key_Left: setText("Alt + Ctrl + Key_Left"); break;
    24. case Qt::Key_Up: setText("Alt + Ctrl + Key_Up"); break;
    25. case Qt::Key_Right: setText("Alt + Ctrl + Key_Right"); break;
    26. case Qt::Key_Down: setText("Alt + Ctrl + Key_Down"); break;
    27. default: setText("Use Only Arrow Keys"); break;
    28. }
    29. }
    30. else
    31. setText("Use Alt + Ctrl");
    32. }
    33. }
    34.  
    35. return false;
    36. }
    37. };
    38.  
    39. int main(int argc, char **argv)
    40. {
    41. QApplication app(argc, argv);
    42.  
    43. Widget widget;
    44. widget.show();
    45.  
    46. return app.exec();
    47. }
    To copy to clipboard, switch view to plain text mode 

    or simple
    Qt Code:
    1. ...
    2. if((Qt::ControlModifier | Qt::AltModifier) & f_event->modifiers())
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by Santosh Reddy; 4th September 2013 at 07:27.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    fine bro its working but the problem is as soon as i press Alt+Ctrl it going to default case (Use Only Arrow Keys), Alt+Ctrl+any arrow key it is going to default case only.

    i have done as below

    Qt Code:
    1. void CBoxViewItem::keyPressEvent(QKeyEvent* f_event)
    2. {
    3. if(f_event->KeyPress)
    4. {
    5. QKeyEvent * keyEvent = static_cast<QKeyEvent *>(f_event);
    6.  
    7. if(f_event->type() == QEvent::KeyPress)
    8. {
    9. if(f_event->modifiers().testFlag(Qt::AltModifier) && f_event->modifiers().testFlag(Qt::ControlModifier) )
    10. {
    11. switch(f_event->key())
    12. {
    13. case Qt::Key_Left:
    14. qDebug()<<"Alt + Ctrl + Key_Left";
    15. break;
    16. case Qt::Key_Up:
    17. qDebug()<<"Alt + Ctrl + Key_Up";
    18. break;
    19. case Qt::Key_Right:
    20. qDebug()<<"Alt + Ctrl + Key_Right";
    21. break;
    22. case Qt::Key_Down:
    23. qDebug()<<"Alt + Ctrl + Key_Down";
    24. break;
    25. default:
    26. qDebug()<<"Use Only Arrow Keys";
    27. break;
    28. }
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 4th September 2013 at 10:07. Reason: code tags

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    Qt Code:
    1. void CBoxViewItem::keyPressEvent(QKeyEvent* f_event)
    2. {
    3. if(f_event->type() == QEvent::KeyPress)
    4. {
    5. if(f_event->modifiers().testFlag(Qt::AltModifier) && f_event->modifiers().testFlag(Qt::ControlModifier) )
    6. {
    7. switch(f_event->key())
    8. {
    9. case Qt::Key_Left:
    10. qDebug()<<"Alt + Ctrl + Key_Left";
    11. break;
    12. case Qt::Key_Up:
    13. qDebug()<<"Alt + Ctrl + Key_Up";
    14. break;
    15. case Qt::Key_Right:
    16. qDebug()<<"Alt + Ctrl + Key_Right";
    17. break;
    18. case Qt::Key_Down:
    19. qDebug()<<"Alt + Ctrl + Key_Down";
    20. break;
    21. default:
    22. qDebug()<<"Use Only Arrow Keys";
    23. break;
    24. }
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    Please may attention while copying the code.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    yes, still i am facing same problem.. its going to default case always .

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    What is your platform and Qt Version, also can post a minimal code to reproduce the problem.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    windows 64-bit and Qt version is 4.8.5, i am using VS2010 by adding Qt plugin


    Qt Code:
    1. void CBoxViewItem::keyPressEvent(QKeyEvent* f_event)
    2. {
    3. if(f_event->KeyPress)
    4. {
    5. if(f_event->type() == QEvent::KeyPress)
    6. {
    7. if(f_event->modifiers().testFlag(Qt::AltModifier) && f_event->modifiers().testFlag(Qt::ControlModifier).)
    8. {
    9. switch(f_event->key())
    10. {
    11. case Qt::Key_Left:
    12. qDebug()<<"Alt + Ctrl + Key_Left";
    13. break;
    14. case Qt::Key_Up:
    15. qDebug()<<"Alt + Ctrl + Key_Up";
    16. break;
    17. case Qt::Key_Right:
    18. qDebug()<<"Alt + Ctrl + Key_Right";
    19. break;
    20. case Qt::Key_Down:
    21. qDebug()<<"Alt + Ctrl + Key_Down";
    22. break;
    23. default:
    24. qDebug()<<"Use Only Arrow Keys";
    25. break;
    26. }
    27. }
    28. else
    29. qDebug()<<"Use Alt + Ctrl";
    30. }
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    this is always going to default case only.
    Last edited by high_flyer; 4th September 2013 at 11:24. Reason: code tags

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    When the default case executes what is the value in f_event->key()?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    16777249

    http://www.codeproject.com/Questions...inations-in-QT
    he is saying that it is working in xp but not in Win7

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    This code:
    Qt Code:
    1. void CBoxViewItem::keyPressEvent(QKeyEvent* f_event)
    2. {
    3. if(f_event->KeyPress)
    4. {...}
    To copy to clipboard, switch view to plain text mode 

    Should not compile.
    Are you sure this is the code you are compiling?

    And please: use code tags when you post code its hard to read it that way.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    yes the same code i am compiling .

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    Strange, since QKeyEvent doesn't have a member called 'KeyPress'.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    and sorry for inconvenience i am new to blog .

    don't knw suddenly its working for for some time in between and stops working again .

  14. #14
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: i need to use Alt+Ctrl+arrow keys combination

    Finally came to know what is the problem... in the scene we have to set focus (item->setFocus(); QGraphicsScene::keyPressEvent(event); ) to the selected item then scene pass that event to that selected item...

    - thank you Santosh Reddy .

Similar Threads

  1. Detect Arrow Keys
    By Ebonair in forum Qt Programming
    Replies: 4
    Last Post: 1st October 2010, 03:55
  2. Replies: 2
    Last Post: 4th August 2010, 20:10
  3. Replies: 5
    Last Post: 10th March 2010, 15:50
  4. Replies: 1
    Last Post: 6th July 2009, 13:48
  5. How can I associate arrow keys?
    By Mariane in forum Newbie
    Replies: 2
    Last Post: 20th January 2006, 18:31

Tags for this Thread

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.