Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to enable FileMenu items with a variable?
Forum Updated to NodeBB v4.3 + New Features

How to enable FileMenu items with a variable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 216 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vijaychsk
    wrote on last edited by
    #1

    In my application, I have 3 different items under FileMenu and each item is individually connected with an appropriate action. But the user cannot accidentally open Work1 and Work2 without Dirs already opening. So, the sequence of operations is like Open Dirs (a map will record this dir path), and then the user has a choice whether to open Work1 or Work2 or both or nothing at all.

    My idea is to hide Work1 and Work2 at the beginning of the application and automatically reactivate these items as soon as the appropriate action becomes valid to operate (meaning Dirs isn't empty). Everything is in the background and the user doesn't know about it.

    The only way that I know the opening Dirs is 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);
    
    jsulmJ 1 Reply Last reply
    0
    • V vijaychsk

      In my application, I have 3 different items under FileMenu and each item is individually connected with an appropriate action. But the user cannot accidentally open Work1 and Work2 without Dirs already opening. So, the sequence of operations is like Open Dirs (a map will record this dir path), and then the user has a choice whether to open Work1 or Work2 or both or nothing at all.

      My idea is to hide Work1 and Work2 at the beginning of the application and automatically reactivate these items as soon as the appropriate action becomes valid to operate (meaning Dirs isn't empty). Everything is in the background and the user doesn't know about it.

      The only way that I know the opening Dirs is 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);
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved