How to enable FileMenu items with a variable?
-
In my application, I have 3 different items under
FileMenuand each item is individually connected with an appropriate action. But the user cannot accidentally openWork1andWork2withoutDirsalready opening. So, the sequence of operations is likeOpen Dirs(a map will record this dir path), and then the user has a choice whether to openWork1orWork2or both or nothing at all.My idea is to hide
Work1andWork2at the beginning of the application and automatically reactivate these items as soon as the appropriate action becomes valid to operate (meaningDirsisn't empty). Everything is in the background and the user doesn't know about it.The only way that I know the opening
Dirsis successful is by checking if the map is empty or not. Is there a better way to handle this situation?QMenu* fileMenu = _menuBar->addMenu(tr("&File")); QAction* action = new QAction("Open &Dirs", this); connect(action, SIGNAL(triggered()), this, SLOT(OnDirOpen())); filemenu->addAction(action); fileMenu->addSeparator(); QAction* action = new QAction("Open &Work1", this); connect(action, SIGNAL(triggered()), this, SLOT(OnWork1Open())); filemenu->addAction(action); fileMenu->addSeparator(); QAction* action = new QAction("Open &Work2", this); connect(action, SIGNAL(triggered()), this, SLOT(OnWork2Open())); filemenu->addAction(action); -
In my application, I have 3 different items under
FileMenuand each item is individually connected with an appropriate action. But the user cannot accidentally openWork1andWork2withoutDirsalready opening. So, the sequence of operations is likeOpen Dirs(a map will record this dir path), and then the user has a choice whether to openWork1orWork2or both or nothing at all.My idea is to hide
Work1andWork2at the beginning of the application and automatically reactivate these items as soon as the appropriate action becomes valid to operate (meaningDirsisn't empty). Everything is in the background and the user doesn't know about it.The only way that I know the opening
Dirsis successful is by checking if the map is empty or not. Is there a better way to handle this situation?QMenu* fileMenu = _menuBar->addMenu(tr("&File")); QAction* action = new QAction("Open &Dirs", this); connect(action, SIGNAL(triggered()), this, SLOT(OnDirOpen())); filemenu->addAction(action); fileMenu->addSeparator(); QAction* action = new QAction("Open &Work1", this); connect(action, SIGNAL(triggered()), this, SLOT(OnWork1Open())); filemenu->addAction(action); fileMenu->addSeparator(); QAction* action = new QAction("Open &Work2", this); connect(action, SIGNAL(triggered()), this, SLOT(OnWork2Open())); filemenu->addAction(action);@vijaychsk said in How to enable FileMenu items with a variable?:
The only way that I know the opening Dirs is successful is by checking if the map is empty or not
Not sure what map you mean, but you also can disable menus/actions and enable them when needed. So, in OnDirOpen() you can enable the other two actions if loading succeeds.