Results 1 to 2 of 2

Thread: Get pressed keys (no modifiers) from QMouseEvent

  1. #1
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Get pressed keys (no modifiers) from QMouseEvent

    Hi,

    I would like to find out if the user pressed a key on the keyboard when clicking a mouse button on a widget. Unfortunately, the QMouseEvent carries only the information about the KeyboardModifiers, but I want to find out whether a letter key is pressed, let's say P+Left click.

    Does anyone know how to achieve this?

    Many thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Get pressed keys (no modifiers) from QMouseEvent

    You can get the key press in the key press event.
    And the mouse event in the mouse event.

    To find out if a key press event is happening at the same time as a mouse event, create your code in such a way that you hold a boolean (example isKeyDown) and a char (the actual key). Set the boolean to true when a key is down (watch out for repeats and input in widgets). Set it to false on key up. Then in the mouse event check that value of the boolean and the char.

    Thinking out of the box.

  3. The following user says thank you to tbscope for this useful post:

    mariposa (25th September 2010)

Similar Threads

  1. how to catch qMouseEvent
    By pakine in forum Newbie
    Replies: 4
    Last Post: 27th June 2012, 10:47
  2. QMouseEvent
    By Fallen_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2010, 05:17
  3. QMouseEvent
    By shenakan in forum Newbie
    Replies: 1
    Last Post: 20th August 2009, 14:53
  4. Catch pressed keys
    By jano_alex_es in forum Newbie
    Replies: 5
    Last Post: 30th July 2009, 12:32
  5. Access Specifiers, Modifiers and Qualifiers
    By sunil.thaha in forum General Programming
    Replies: 4
    Last Post: 8th March 2006, 12:07

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.