Results 1 to 8 of 8

Thread: checkable QAction shortcut hold

  1. #1
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default checkable QAction shortcut hold

    Hello

    Suppose u have a chackable action, with a key shortcut assigned to it. When the key is pressed, the action is checked. When the key is pressed again, the action is un-checked.

    Everything works fine, as long as the user just presses the key and releases it quickly. But if for some reason the key stays pressed, then the action is checked and then unchecked and so on, continuously, until the key is released!

    Why is there such a behavior? Is there any work around?

    thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: checkable QAction shortcut hold

    Quote Originally Posted by winder View Post
    Why is there such a behavior? Is there any work around?
    It's the default behavior like everywhere. If you are in a text editor and hold a key, then first only one is inserted but aber some miliseconds more letters are inserted.

    A workaaround could be to connect the shortcut to an extra slot where you implement a wait condition before altering the check status again.

  3. #3
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: checkable QAction shortcut hold

    i started setting flags in keyPressed and keyReleased events... only to realize that when a key is being held down, pressed and released events are sent.... even though you have never released the key!! How misleading... You can never be sure, if a key release event happened when a key is actually released, or when a key stayed down for too long...

    i'm confused... maybe a code example can clear things out...
    Last edited by winder; 18th February 2010 at 02:05.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkable QAction shortcut hold

    What happens if you set your action autorepeat as false ?
    QAction::setAutoRepeat(false)

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: checkable QAction shortcut hold

    Quote Originally Posted by aamer4yu View Post
    QAction::setAutoRepeat(false)
    D'oh! nice...

  6. #6
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: checkable QAction shortcut hold

    Thatnks!! That's what i was looking for!

    Great! thank you.

  7. #7
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: checkable QAction shortcut hold

    I have a related question, so i post it here, rather than posting a new thread.

    i have a 3d viewport, and i want the user to be able to navigate around the scene when mouse is moved while ALT key is pressed. So what i want to do, is check inside a mouseMove event, if alt key is pressed. The thing is, i don't know how to do that!

    I also think that, maybe this way, auto repeat will still be a problem, since i'm not dealing with a particular action, to just call the setAutoRepeat(false).

    Thanks again.

  8. #8
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: checkable QAction shortcut hold

    For the auto repeat issue inside a key event handler, i think this is the solution.... bool QKeyEvent::isAutoRepeat () const

    Now how can i use alt in conjunction with mouse?

Similar Threads

  1. Checkable QLineEdit ?
    By olidem in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2009, 16:47
  2. QAction shortcut
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2009, 20:35
  3. QTextEdit does not hold Object Id behind
    By validator in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2008, 00:25
  4. checkable item
    By gyre in forum Newbie
    Replies: 1
    Last Post: 23rd November 2007, 07:44
  5. QListWidgetItem checkable
    By mikro in forum Newbie
    Replies: 1
    Last Post: 16th July 2006, 14:22

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.