The code is below. Some things are missing, but I hope it's clear.. Thanks!
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()));
}
}
void Tray::createMenu()
{
trayIconMenu = new QMenu(this);
fileMenu = trayIconMenu->addMenu("Change active profile");
connect(fileMenu, SIGNAL(aboutToShow()), this, SLOT(activateFileMenu()));
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}
void Tray::activateFileMenu()
{
fileMenu->clear();
QList<QString> allfiles = files->getAllFiles(); // retrieve file names
fileGroupAction = new QActionGroup(this);
QAction *fileAction;
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()));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks