Results 1 to 3 of 3

Thread: Assign shortcut only

  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default Assign shortcut only

    Hi,

    BrushColorAction is a QAction assigned a shortcut (Ctrl + C) and is added in a menu.

    brushColorAction = new QAction(tr("&Brush Color..."), this);
    brushColorAction->setShortcut(tr("Ctrl+C"));
    connect(brushColorAction, SIGNAL(triggered()),
    this, SLOT(brushColorAct()));

    void brushColorAct() { .. QColorDialog * dlg = new QColorDialog; .... }

    If I want to remove the menu but keep the shortcut (Ctrl + C) to invoke the color dialog,
    how to do it ? Thank your replay.
    Last edited by chiaminhsu; 8th February 2013 at 16:18.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Assign shortcut only

    If I want to remove the menu but keep the shortcut (Ctrl + C) to invoke the color dialog,
    how to do it ?
    Don't add to QMenu, Just create the QAction, set the shortcut, and add the action to dialog
    Qt Code:
    1. MyDialog * dialog = new MyDialog;
    2. brushColorAction = new QAction(tr("&Brush Color..."), dialog);
    3. brushColorAction->setShortcut(tr("Ctrl+C"));
    4. dialog->connect(brushColorAction, SIGNAL(triggered()), SLOT(brushColorAct()));
    5. dialog->addAction(brushColorAction);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    chiaminhsu (9th February 2013)

  4. #3
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default Re: Assign shortcut only

    Thank you very much. It works, I also learn that addAction() more advancedly

Similar Threads

  1. How to Assign a Variable into LineEdit
    By mcht_z in forum Newbie
    Replies: 2
    Last Post: 18th February 2011, 20:55
  2. How to assign IP address to eth0 in QT
    By csw00700 in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2011, 14:31
  3. Assign shortcut keys to buttons
    By mecrazycoder in forum Newbie
    Replies: 0
    Last Post: 7th January 2011, 23:42
  4. How to correctly re-assign a pointer?
    By homerun4711 in forum Newbie
    Replies: 26
    Last Post: 4th January 2011, 17:39
  5. boost::assign
    By Sivert in forum General Programming
    Replies: 0
    Last Post: 2nd May 2007, 01:23

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.