Results 1 to 2 of 2

Thread: QShortcut - doesn't work with Qt::Key_Return

  1. #1
    Join Date
    Feb 2006
    Location
    Warsaw, Poland
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QShortcut - doesn't work with Qt::Key_Return

    Hi there! I'm trying to create shortcuts in my app. Here is some code:

    Qt Code:
    1. (void) new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Enter), this, SLOT(insertNl()));
    2. (void) new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Return), this, SLOT(insertNl()));
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. if(obj==input)
    2. if(ev->type()==QEvent::KeyPress)
    3. {
    4. QKeyEvent *keyEvent=static_cast<QKeyEvent*>(ev);
    5. if(keyEvent->key()==Qt::Key_Return || keyEvent->key()==Qt::Key_Enter)
    6. {
    7. sendMsg();
    8. return true;
    9. }
    10. }
    11. return QDialog::eventFilter(obj,ev);
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by naresh; 7th April 2006 at 15:15.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QShortcut - doesn't work with Qt::Key_Return

    QTextEdit uses the return key for its own purposes. You have to catch it before it reaches QTextEdit (using an event filter for example).

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.