Results 1 to 3 of 3

Thread: How to enable shortcut keys for custom widgets?

  1. #1
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to enable shortcut keys for custom widgets?

    I am trying to implement a customized QTableView integrated to the clipboard:

    Qt Code:
    1. #include <QTableView>
    2. #include <QAction>
    3.  
    4. class GeneralTableView : public QTableView
    5. {
    6. Q_OBJECT
    7. public:
    8. explicit GeneralTableView(QWidget *parent = 0);
    9.  
    10. public slots:
    11. void copy();
    12.  
    13. protected:
    14. QAction* copyAction_;
    15. };
    16.  
    17. GeneralTableView::GeneralTableView(QWidget *parent) :
    18. QTableView(parent)
    19. {
    20. copyAction_ = new QAction(this);
    21. copyAction_->setShortcut(QKeySequence::Copy);
    22. connect(copyAction_, SIGNAL(triggered()),
    23. this, SLOT(copy()));
    24. }
    To copy to clipboard, switch view to plain text mode 

    But copy() does not get executed when I hit ctrl+c. Only some default version of copy gets called. This copies only one cell in the clipboard and doesn't call my copy(). How can I fix this?

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to enable shortcut keys for custom widgets?

    It will only get trigger when you have something to copy. Since you dont have anything then how it would get trigger? What it will copy?
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to enable shortcut keys for custom widgets?

    I have an implementation for copy(), I just did not want to include it here for brevity. If I call copy() in another way, for example from a context menu, it does what it is supposed to do. It copies the entire selection to the clipboard. My problem is that it doesn't get called when I hit ctrl+c.

Similar Threads

  1. how to set user defined shortcut keys in menu
    By gauravg in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2011, 10:31
  2. Shortcut keys??
    By Zingam in forum Qt Quick
    Replies: 1
    Last Post: 20th July 2011, 08:53
  3. Shortcut, some keys won't work
    By smoon in forum Qt Programming
    Replies: 0
    Last Post: 27th February 2011, 11:19
  4. Assign shortcut keys to buttons
    By mecrazycoder in forum Newbie
    Replies: 0
    Last Post: 7th January 2011, 22:42
  5. disable/enable shortcut
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 10:58

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.