View Full Version : QShortcut - doesn't work with Qt::Key_Return

7th April 2006, 13:39
Hi there! I'm trying to create shortcuts in my app. Here is some code:

(void) new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Enter), this, SLOT(insertNl()));
(void) new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Return), this, SLOT(insertNl()));

The problem is that shortcut with Qt::Key_Return doesn't work. Later in code I have event filter

QKeyEvent *keyEvent=static_cast<QKeyEvent*>(ev);
if(keyEvent->key()==Qt::Key_Return || keyEvent->key()==Qt::Key_Enter)
return true;
return QDialog::eventFilter(obj,ev);

And with eventFilter both keys works. Anyone experienced such problem?

I've found out that shortcut with Qt::Key_Return doesn't work only when I'm focused in QTextEdit. Unfortunetly I need it to work in this QTextEdit. Any ideas how to do that?

12th April 2006, 12:00
QTextEdit uses the return key for its own purposes. You have to catch it before it reaches QTextEdit (using an event filter for example).