Results 1 to 3 of 3

Thread: Changing Menubar items dynamically Based on what page is currently being displayed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Changing Menubar items dynamically Based on what page is currently being displayed

    HI,

    In my Qt Mobile app, I have a situation where the Options Menubar items should be changed dynamically based on the page (Stackedwidget) currently being displayed. Can any one please guide me in this.

    Thank You,
    Baluk.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Changing Menubar items dynamically Based on what page is currently being displaye

    Let every page have a function that returns a menu. Then when the page changes, substitute the menu in the menubar.

  3. #3
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing Menubar items dynamically Based on what page is currently being displaye

    Hi,

    I did some coding accordingly. The menu is substituted successfully but this works only after the new menu instance is added next to the default menu. I can't able to remove the default one from menu bar.

    Here I am placing the code and image of the app. Please suggest me how can I overcome this problem.

    Qt Code:
    1. calculateHelper::calculateHelper(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::calculateHelper)
    4. {
    5. ui->setupUi(this);
    6. b = new QMenuBar(this);
    7. setMenuBar(b);
    8. page_1 = new QMenu(tr("&Main"),this);
    9. page_2 = new QMenu(tr("&Edit"),this);
    10. page_3 = new QMenu(tr("&Reminder"),this);
    11. optionsmenu();
    12. ui->stackedWidget->setCurrentIndex(0);
    13. b->addMenu(page_1);
    14. }
    15.  
    16. void calculateHelper::optionsMenu()
    17. {
    18. created the actions for all the menus
    19. }
    20. void calculateHelper::indexChange(int i)
    21. {
    22.  
    23. switch(i)
    24. {
    25. case 0: b->clear();
    26. page_1->clear();
    27. b->addMenu(page_1);
    28. break;
    29. case 1: b->clear();
    30. b->addMenu(page_2);
    31. break;
    32. case 2:b->clear();
    33. b->addMenu(page_3);
    34. default: break;
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. Replies: 0
    Last Post: 6th May 2010, 12:13
  2. Dynamically changing QFrame color
    By Doug Broadwell in forum Newbie
    Replies: 6
    Last Post: 16th October 2008, 08:22
  3. Dynamically changing QLabel background colour
    By T4ng10r in forum Qt Programming
    Replies: 19
    Last Post: 19th April 2007, 12:47
  4. Dynamically changing QGroupBox size
    By T4ng10r in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 15:02

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.