PDA

View Full Version : Changing Menubar items dynamically Based on what page is currently being displayed



baluk
28th September 2010, 09:11
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.

tbscope
28th September 2010, 09:16
Let every page have a function that returns a menu. Then when the page changes, substitute the menu in the menubar.

baluk
28th September 2010, 11:34
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.




calculateHelper::calculateHelper(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::calculateHelper)
{
ui->setupUi(this);
b = new QMenuBar(this);
setMenuBar(b);
page_1 = new QMenu(tr("&Main"),this);
page_2 = new QMenu(tr("&Edit"),this);
page_3 = new QMenu(tr("&Reminder"),this);
optionsmenu();
ui->stackedWidget->setCurrentIndex(0);
b->addMenu(page_1);
}

void calculateHelper::optionsMenu()
{
created the actions for all the menus
}
void calculateHelper::indexChange(int i)
{

switch(i)
{
case 0: b->clear();
page_1->clear();
b->addMenu(page_1);
break;
case 1: b->clear();
b->addMenu(page_2);
break;
case 2:b->clear();
b->addMenu(page_3);
default: break;
}
}