Results 1 to 2 of 2

Thread: How do you add a QActionGroup to a QMenuBar?

  1. #1
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How do you add a QActionGroup to a QMenuBar?

    Just wondering how to add a QActionGroup to a QMenuBar?

    I know how to add a QAction, just can't find how to add a QActionGroup.

    You need to setup the QActionGroup before its added, right?

    Thanks in advance
    Brendan

  2. #2
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do you add a QActionGroup to a QMenuBar?

    Yeah I worked it out:

    Qt Code:
    1. //////////////////
    2. // Setup menu bar.
    3. //////////////////
    4. QAction *menuAction;
    5. QActionGroup *menuActionGroup = new QActionGroup(this);
    6. QMenuBar *menuBar = new QMenuBar(this);
    7.  
    8. QMenu *menu = menuBar->addMenu("File");
    9. menuAction = menu->addAction("Load");
    10. connect(menuAction, SIGNAL(triggered()), this, SLOT(Load_Configuration()));
    11. menuAction = menu->addAction("Save");
    12. connect(menuAction, SIGNAL(triggered()), this, SLOT(Save_Configuration()));
    13.  
    14. menuActionGroup->setExclusive(true);
    15. menu = menuBar->addMenu("ComPort");
    16. menuAction = menu->addAction("No Port");
    17. menuAction->setChecked(true);
    18. menuAction->setCheckable(true);
    19. menuActionGroup->addAction(menuAction);
    20. connect(menuAction, SIGNAL(triggered()), this, SLOT(Select_ComPort0()));
    21. menuAction = menu->addAction("Com 1");
    22. menuAction->setCheckable(true);
    23. menuActionGroup->addAction(menuAction);
    24. connect(menuAction, SIGNAL(triggered()), this, SLOT(Select_ComPort1()));
    25. menuAction = menu->addAction("Com 2");
    26. menuAction->setCheckable(true);
    27. menuActionGroup->addAction(menuAction);
    28. connect(menuAction, SIGNAL(triggered()), this, SLOT(Select_ComPort2()));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Question about "delete" on QMenuBar instance..
    By tgreaves in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2009, 22:10
  2. Hide Qmenubar
    By user_mail07 in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 22:16
  3. QDialog and QMenuBar
    By lutins in forum General Programming
    Replies: 4
    Last Post: 13th September 2008, 14:39
  4. QActionGroup question
    By maverick_pol in forum Qt Programming
    Replies: 7
    Last Post: 6th October 2007, 18:34
  5. where could QPopupMenu show besides QMenuBar !
    By bigbigmoon in forum Newbie
    Replies: 4
    Last Post: 2nd November 2006, 01:03

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.