Results 1 to 3 of 3

Thread: mapping menu item with QPushButton

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default mapping menu item with QPushButton

    Hi,
    Can any one please tell, is it possible to map menu item with a normal button in the main window. For example:
    Menu has a checkable sub item called EDIT and there is a QPushButton called EDIT in mainwindow . This both should synchronise i.e when i click subitem EDIT, then mainwindow EDIT should turn to checked state.

    Can any one help me out????

  2. #2
    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: mapping menu item with QPushButton

    is this what you what?
    Qt Code:
    1. ...
    2. QAction *action = new QAction(tr("Action"), this);
    3. action->setCheckable(true);
    4.  
    5. QMenu *menu = menuBar()->addMenu(tr("File"));
    6. menu->addAction(action);
    7.  
    8. QPushButton *pb = new QPushButton(tr("Button"), this);
    9. pb->setCheckable(true);
    10.  
    11. connect(action, SIGNAL(toggled(bool)), pb, SLOT(setChecked(bool)));
    12. connect(pb, SIGNAL(toggled(bool)), action, SLOT(setChecked(bool)));
    13. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2006
    Location
    belgium
    Posts
    14
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mapping menu item with QPushButton

    but shouldn't this happen automatically when you would also add the action to the button? like:
    Qt Code:
    1. pb->addAction(action);
    To copy to clipboard, switch view to plain text mode 
    it seems unintuitive to me that I would have to manually connect signal/slot if that would exactly seem like an advantage of using an action in multiple places that you don't have to connect it each time..?

    in any case, I tried it by adding the action to the toggle button, but it doesn't work. So that's why I started searching the net and ended up here I just would like confirmation from a qt guru that manually connecting the signal/slot is the right thing to do..

Similar Threads

  1. creating a "path" for the menu item
    By roxton in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2009, 16:32
  2. Menu Item has no highlight
    By blackfox in forum Qt Programming
    Replies: 6
    Last Post: 24th September 2008, 12:17
  3. Background image on popup menu item
    By MarkoSan in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th June 2006, 05:55
  4. Qt/MacOSX preferences menu item
    By mcenatie in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2006, 04:24
  5. image for a custom menu Item.......
    By Naveen in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2006, 09:28

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.