Results 1 to 3 of 3

Thread: QShortcut in QWidget

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QShortcut in QWidget

    From MainWindow I cretae simple QWidget which has a construct in the construct i have the code below to call an action on Enter (key), but that does not being called.

    Qt Code:
    1. QShortcut *ok = new QShortcut(this);
    2. ok->setKey(Qt::Key_Enter);
    3. connect(ok, SIGNAL(activated()), this, SLOT(action()));
    To copy to clipboard, switch view to plain text mode 

    in MainWindow:

    Qt Code:
    1. Dialog *d = new Dialog(this);
    2. d->show();
    To copy to clipboard, switch view to plain text mode 

    Am I doing something wrong, The Dialog should has focus on show() right ? or not ?


    when I use:

    Qt Code:
    1. ok->setKey(QKeySequence::Delete);
    To copy to clipboard, switch view to plain text mode 

    works fine but there is no QKeySequence::Enter ???

    Tried also
    Qt Code:
    1. void Dialog::keyPressEvent(QKeyEvent * event)
    To copy to clipboard, switch view to plain text mode 

    but event->text() returns empty value


    Any ideas ??
    Last edited by migel; 9th August 2011 at 12:42.

  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 in QWidget

    For shortcuts to work, they need to be attached to some visible and active element such as a button, menu or widget with focus. By the way, there is Key_Enter and Key_Return, make sure you're using the right one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    migel (9th August 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QShortcut in QWidget

    the winner is Qt::Key_Return instead of Qt::Key_Enter

    many thanks

Similar Threads

  1. QShortcut not always working
    By jörg in forum Qt Programming
    Replies: 7
    Last Post: 8th June 2011, 16:59
  2. QShortcut not work!
    By leeeryan in forum Newbie
    Replies: 1
    Last Post: 16th December 2010, 09:27
  3. QShortcut SIGNAL must be of 0 arguments?
    By Wasabi in forum Newbie
    Replies: 1
    Last Post: 17th August 2010, 21:26
  4. QShortcut not working
    By berinder in forum Qt Programming
    Replies: 0
    Last Post: 24th November 2008, 10:20
  5. QShortcut
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2008, 10:42

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.