PDA

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



naresh
7th April 2006, 14: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


if(obj==input)
if(ev->type()==QEvent::KeyPress)
{
QKeyEvent *keyEvent=static_cast<QKeyEvent*>(ev);
if(keyEvent->key()==Qt::Key_Return || keyEvent->key()==Qt::Key_Enter)
{
sendMsg();
return true;
}
}
return QDialog::eventFilter(obj,ev);

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

//EDIT
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?

wysota
12th April 2006, 13: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).