PDA

View Full Version : checkable QAction shortcut hold



winder
17th February 2010, 21:46
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

Lykurg
17th February 2010, 22:06
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.

winder
17th February 2010, 23:25
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...

aamer4yu
18th February 2010, 06:31
What happens if you set your action autorepeat as false ?
QAction::setAutoRepeat(false)

Lykurg
18th February 2010, 07:24
QAction::setAutoRepeat(false)
D'oh! nice...

winder
18th February 2010, 11:55
Thatnks!! That's what i was looking for!

Great! thank you.

winder
18th February 2010, 15:21
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.

winder
18th February 2010, 15:48
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?