Results 1 to 9 of 9

Thread: Setting Hotkey Shortcuts

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting Hotkey Shortcuts

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb Re: Setting Hotkey Shortcuts

    One way could be more or less like this:
    Qt Code:
    1. QShortcut* shorcut = new QShortcut(Qt::Key_Enter, textEdit);
    2. connect(shortcut, SIGNAL(triggered()), button, SLOT(click()));
    To copy to clipboard, switch view to plain text mode 

    Another option could be to use a QShortcut with Qt::WindowShortcut context.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    VireX (3rd April 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting Hotkey Shortcuts

    Thanks again jpn.

  5. #4
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting Hotkey Shortcuts

    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.
    Last edited by VireX; 3rd April 2007 at 21:04.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting Hotkey Shortcuts

    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.

    Qt Code:
    1. QShortcut* shorcut = new QShortcut(Qt::Key_Enter, textEdit);
    2. shortcut->setContext(Qt::WidgetShortcut);
    3. connect(shortcut, SIGNAL(activated()), button, SLOT(click()));
    4. connect(shortcut, SIGNAL(activatedAmbiguously()), button, SLOT(click()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. #6
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting Hotkey Shortcuts

    It's still not working. Pressing Enter Key does not do anything.

    activated and activatedAmbiguously are definitely not being signalled.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting Hotkey Shortcuts

    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.

  9. The following user says thank you to jacek for this useful post:

    VireX (4th April 2007)

  10. #8
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting Hotkey Shortcuts

    Oh, I have a laptop. I thought Enter key and Return key were synonymous.

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting Hotkey Shortcuts

    Quote Originally Posted by VireX View Post
    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.

Similar Threads

  1. QAction shortcuts from QLineEdit
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 15:43
  2. Setting style in QApplication
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 28th October 2006, 21:56
  3. form setting
    By mickey in forum Qt Tools
    Replies: 5
    Last Post: 27th September 2006, 00:28
  4. Replies: 1
    Last Post: 18th March 2006, 16:37
  5. Menu shortcuts in Visual Studio?
    By kw in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2006, 23:30

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.