View Full Version : Setting Hotkey Shortcuts
VireX
3rd April 2007, 20:28
I have a textedit named txtedit... and I have a sendbutton. But I have 3 of each in separate tabs.
I usually do:
sendbutton->setShortcut(Qt::Key_Enter);
sendbutton2->setShortcut(Qt::Key_Enter);
sendbutton3->setShortcut(Qt::Key_Enter);
What I really want to do is, make all the txtedit's shortcut as the button.
In other words, when a guy clicks on a txtedit types a message and then presses enter, it sends the message.
So far, it's failing. Any other method? Perhaps I need to use connect()?
Thanks for help.
One way could be more or less like this:
QShortcut* shorcut = new QShortcut(Qt::Key_Enter, textEdit);
connect(shortcut, SIGNAL(triggered()), button, SLOT(click()));
Another option could be to use a QShortcut with Qt::WindowShortcut context.
VireX
3rd April 2007, 20:46
Thanks again jpn.
VireX
3rd April 2007, 20:56
Wait a second this didn't work.
QShortcut* shortcut0 = new QShortcut(Qt::Key_Enter, ChatSend_0);
QShortcut* shortcut1 = new QShortcut(Qt::Key_Enter, ChatSend_1);
QShortcut* shortcut2 = new QShortcut(Qt::Key_Enter, ChatSend_2);
connect(shortcut0, SIGNAL(triggered()), Send_0, SLOT(click()));
connect(shortcut1, SIGNAL(triggered()), Send_1, SLOT(click()));
connect(shortcut2, SIGNAL(triggered()), Send_2, SLOT(click()));
None of the shortcuts work, very odd.
It could be an ambiguous shortcut. A QShortcut seems the have the "window" context by default. Also, the correct signal seems to be activated, not triggered.. sorry.
QShortcut* shorcut = new QShortcut(Qt::Key_Enter, textEdit);
shortcut->setContext(Qt::WidgetShortcut);
connect(shortcut, SIGNAL(activated()), button, SLOT(click()));
connect(shortcut, SIGNAL(activatedAmbiguously()), button, SLOT(click()));
VireX
3rd April 2007, 22:46
It's still not working. Pressing Enter Key does not do anything.
activated and activatedAmbiguously are definitely not being signalled.
jacek
3rd April 2007, 23:30
Are you sure you are pressing the Enter key? Usually it's in the lower-right corner of the numeric keypad.
Try creating shorcut for Qt::Key_Return.
VireX
4th April 2007, 01:36
Oh, I have a laptop. I thought Enter key and Return key were synonymous.
jacek
4th April 2007, 22:22
I thought Enter key and Return key were synonymous.
Once I thought the same. IMO, the safest solution is to create two shorcuts --- one for each of those keys.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.