Results 1 to 5 of 5

Thread: Own function in widget menu when right click.

  1. #1
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Own function in widget menu when right click.

    I know the thread title is a bit confusing but that's because I don't know how to call it.
    What I want to get is, when I right-click on some widget i.e. spinBox I get this:

    but I'd like to add to this list my own functions. Any idea how to do it?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Own function in widget menu when right click.


  3. #3
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Own function in widget menu when right click.

    Humm, so far I managed to do:

    Qt Code:
    1. QAction* randomize = new QAction(this);
    2. randomize->setText("Randomize");
    3. connect(randomize, SIGNAL(triggered()), this, SLOT(test()));
    4. ui->spinBox->addAction(randomize);
    To copy to clipboard, switch view to plain text mode 

    and changed in desinger, spinBox contextMenuPolicy to actionsContextMenu.

    This works fine but I want to keep the default options (Undo, redo, copy, paste etc.) and only append mine option at the end.

    I checked what you gave me there Lykurg, but cannot figure out much of this.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Own function in widget menu when right click.

    actionsContextMenu
    Should be CustomContextMenu! Use the emited customContextMenuRequested signal and connect it to your own slot. There you fetch the widgets actions via QWidget:actions() create a menu out of them, add your own actions and and execute it.

    OR

    set to actionsContextMenu, use the way you mentioned by adding the custom functions to the widget and it should work


    EDIT: If you want the same look and feel use createStandardContextMenu() and alter the retrieved QMenu with your own actions.

    Sorry for the confusing answers, but you will find all necessary informations...
    Last edited by Lykurg; 11th June 2009 at 20:13.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Own function in widget menu when right click.

    maybe this can help you.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.