+ Reply to Thread
Results 1 to 13 of 13

Thread: Help with QT shortcuts?

  1. #1
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Help with QT shortcuts?

    Hi there. I'm trying to make it so that the "aButton" will be pressed when the user presses the a key on the keyboard.

    This is my code thus far. It compiles and runs, but pressing the a key on the keyboard does nothing.

    QPushButton *aButton=new QPushButton("&aButton", this);

    QShortcut aShortCut = new QShortcut(QKeySequence(Qt::Key_A), this);
    QObject::connect(aShortCut, SIGNAL(clicked()), this, SLOT(toggle()));

    Any ideas why it's not working?

    Thanks!

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QT shortcuts?

    you are connecting the wrong slot of the wrong object. Infact everything is wrong.

    try this.
    Qt Code:
    1. QObject::connect(aShortCut, SIGNAL(activated()), aButton, SLOT(animateClick()));
    To copy to clipboard, switch view to plain text mode 

    by the way,, the "&aButton" should be working as auto shortcut

  3. #3
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Help with QT shortcuts?

    Mmmkay. I changed the QObject line like you said and it still isn't working.

    Not sure what you mean by "should be working as auto shortcut."

    I'm a newbie to QT, so I apologize ahead of time for my lack of knowledge.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QT shortcuts?

    read the documentation of QShortCut and QAbstractButton, you just might be doing a little mistake here and there....
    Can you post a minimal compilable program reproducing the problem?

  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help with QT shortcuts?


  6. #6
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Help with QT shortcuts?

    hi,
    as totem said,
    Qt Code:
    1. aButton->setShortcut(Qt::Key_A)
    To copy to clipboard, switch view to plain text mode 
    is the easiest way

    Bala

  7. #7
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Help with QT shortcuts?

    Okay, so I changed the lines to this:

    Qt Code:
    1. QPushButton *aButton=new QPushButton("&aButton", &w);
    2.  
    3. aButton->setShortcut(Qt::Key_A);
    4. // QObject::connect(aShortCut, SIGNAL(activated()), aButton, SLOT(animateClick()));
    To copy to clipboard, switch view to plain text mode 

    (I commented out that last line....I think I was supposed to do that now that I'm using the aButton->setShortcut. Still issue though. It compiles and runs, but the aButton isn't clicked when I press the letter a on my keyboard.

    Any other ideas?

  8. #8
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Help with QT shortcuts?

    are you connecting to any signals at all?
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  9. #9
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Help with QT shortcuts?

    I was before with that last line that I commented out...

  10. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QT shortcuts?

    You need to provide a minimal compilable example reproducing the problem.

  11. #11
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Help with QT shortcuts?

    I'd rather not just post it on here, as it is a school project. Perhaps I can private message it to you? Which files would you need to be able to see the problem?

  12. #12
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Help with QT shortcuts?

    Anyone else have any ideas?

    I need to finish this soon. =/

    I feel like I ALMOST have it...like I'm off by one tiny error or something.

  13. #13
    Join Date
    Feb 2018
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Help with QT shortcuts?

    Working ..............

    QPushButton *aButton=new QPushButton("&aButton", this);
    QShortcut *aShortCut = new QShortcut(QKeySequence(Qt::Key_A), aButton);
    QObject::connect(aShortCut, SIGNAL(activated()), aButton, SLOT(animateClick()));

+ Reply to Thread

Similar Threads

  1. enable shortcuts using Designer
    By szisziszilvi in forum Qt Tools
    Replies: 8
    Last Post: 6th January 2011, 14:03
  2. qml key shortcuts
    By antialias_forum in forum Qt Quick
    Replies: 0
    Last Post: 22nd December 2010, 14:45
  3. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 13:18
  4. Pb with shortcuts on Mac OS
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2008, 19:22
  5. Creatin Key Pad shortcuts
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 19th May 2006, 05:50

Tags for this Thread

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