How to show SubMenu next to MainMenu?
Hi,
I've added a submenu to the main menu with the following command:
subMenu = mainMenu->addMenu("Recent files");
subMenu->addAction(....);
...
The problem is that when I run my application and open subMenu, it's not shown right next to the mainMenu. It might have different positions on the screen and might be not attached to the mainMenu at all.
How to bind the subMenu to the mainMenu?
Thanks for any help!!
Re: How to show SubMenu next to MainMenu?
Can u provide some snapshot of how u want it to appear ?
Also what have u tried ??
2 Attachment(s)
Re: How to show SubMenu next to MainMenu?
The first attached picture is what I have. On the second picture is what I want to have (like it's normally). The first situation happens always when the submenu is shown first time (either when the application has just started or when the content of the submenu has changed). When the same content of the submenu has already been shown once then it's always like on the second picture (but still not perfectly aligned!!).
(The main menu is a contex menu shown when one of the tray icons is triggered. The submenu on the left is shown when action "Change active profile" is triggered).
Re: How to show SubMenu next to MainMenu?
Can u post the code how you are doing it ?
Re: How to show SubMenu next to MainMenu?
The code is below. Some things are missing, but I hope it's clear.. Thanks!
Code:
void Tray::createMenu()
{
trayIconMenu
= new QMenu(this);
fileMenu = trayIconMenu->addMenu("Change active profile");
connect(fileMenu, SIGNAL(aboutToShow()), this, SLOT(activateFileMenu()));
trayIcon->setContextMenu(trayIconMenu);
}
void Tray::activateFileMenu()
{
fileMenu->clear();
QList<QString> allfiles = files->getAllFiles(); // retrieve file names
for (int i = 0; i < allfiles.size(); ++i) { // create a certain number of actions in fileMenu
fileAction
= new QAction (files
->getIcon
(allfiles.
at(i
)), allfiles.
at(i
), fileGroupAction
);
fileAction->setCheckable(true);
if (files->getImportance(allfiles.at(i))==1)
fileAction->setChecked(true); // one of the files is checked by default
fileMenu->addAction(fileAction);
fileGroupAction->addAction(fileAction);
connect(fileAction, SIGNAL(triggered()), this, SLOT(changeActiveFile()));
}
}