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. What is the standard method for updating toolbars and menus?
Forum Updated to NodeBB v4.3 + New Features

What is the standard method for updating toolbars and menus?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.0k Views 1 Watching
  • 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.
  • pcsaganP Offline
    pcsaganP Offline
    pcsagan
    wrote on last edited by
    #1

    I'm coming from an MFC environment where update handlers were written to determine if a particular feature (action) should be enabled or disabled. How do you do the same thing in Qt? For instance, if I have a QAction for saving the active document, then I want to effectively call saveAction.setEnabled(document.isModified()) whenever the action (toolbar, menu, etc) is displayed to the user.

    Is there a built in mechanism to accomplish this already? or are users expected to create a background thread to call all of these update action handlers? or is there perhaps another way of implementing this?

    Thanks

    A mosquito was heard to complain, that chemists had poisoned his brain, the cause of his sorrow was paradichlorodiphenyltrichloroethane.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You don't need to do anything particular. Calling setEnabled when your document is modified is enough. The state of the button will stay until you call setEnabled again with a different value. The toolbar visibility has no influence on the state of that button.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • pcsaganP Offline
        pcsaganP Offline
        pcsagan
        wrote on last edited by
        #3

        Unfortunately that solution does not provide the desired behavior. It would not be acceptable to be forced to manually update the action's enabled state from all the numerous code paths that may modify the document.

        Currently I've implemented the desired behavior by having an updateActionStates() method which sets the action states according to the active document and its modified value, and it is called in an overrided MainWindow::event(QEvent* event). This causes the QAction to reflect the document's modified state without having to manually invoke updateActionStates() when we think the document may have changed.

        The only problem right now is that the updateActionStates() method is likely being invoked far more often than need be, but it's still a vastly superior solution than manually invoking updateActionStates() in 60 different places.

        A mosquito was heard to complain, that chemists had poisoned his brain, the cause of his sorrow was paradichlorodiphenyltrichloroethane.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you are talking about QTextDocument, then you have the modificationChanged property that you can use for that purpose. No need to check each and every code path. The notification changed signal will be emitted by the document itself when changed.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • pcsaganP Offline
            pcsaganP Offline
            pcsagan
            wrote on last edited by
            #5

            I am not dealing with a QTextDocument.

            A mosquito was heard to complain, that chemists had poisoned his brain, the cause of his sorrow was paradichlorodiphenyltrichloroethane.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case, it would be very useful to share a little more details about your code to be able to help you.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • pcsaganP Offline
                pcsaganP Offline
                pcsagan
                wrote on last edited by
                #7

                Perhaps experience with MFC programming is required to fully understand my problem. Thanks for your time.

                A mosquito was heard to complain, that chemists had poisoned his brain, the cause of his sorrow was paradichlorodiphenyltrichloroethane.

                1 Reply Last reply
                0
                • jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  No, experience with MFC is not required. A better description of what widgets you are using is required. What is your document which can be changed? Which Qt widget do you use to show and change it?

                  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