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. EnabledChanged () [signal]
Forum Updated to NodeBB v4.3 + New Features

EnabledChanged () [signal]

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 6.1k 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.
  • N Offline
    N Offline
    nekkceb
    wrote on last edited by
    #1

    It would be convenient if we had a signal, void QAbstractButton::enabledChanged () [signal] to that buttons emit this signal with the enabled state changes. I am surprised it is not there yet! I see QGraphicsObject gets it, but not buttons. I dont have access to the bug or feature list request -- can someone post this if it is felt to be a good idea? If folks think it a bad idea, please tell me why...

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      You can track a status of a property "enabled" using "changeEvent()":http://qt-project.org/doc/qt-5/qwidget.html#enabled-prop

      There was a similar suggestion about "QAction":https://bugreports.qt-project.org/browse/QTBUG-3565 and it was closed.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nekkceb
        wrote on last edited by
        #3

        I saw that, but to use the changeEvent, wouldnt I have to subclass the QPushButton or whatever class to use that? Or write a changeEvent method in a dialog, but then a big loop to figure out who sent the changeEvent to act on it appropriately. If I had a signal emitted, I could just connect objects together using connect() without doing a subclass or write a big changeEvent method. Should be much easier to link objects together whose enabled status need to be linked.

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

          Hi,

          You can also use a an event filter on your button, or create a subclass of QPushButton with that additional signal and use it in your code.

          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
          • N Offline
            N Offline
            nekkceb
            wrote on last edited by
            #5

            thanks again, but I was looking for an even easier solution -- the signal/slot mechanism works pretty well, so if I could just connect two widgets using enabledChanged on one to propagate to the other without making a subclass, to me that is easier, the code would also be simpler than an event filter.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              Yeah, I don't think it is possible without creating your own widget.
              But you don't need to implement the whole widget logic.
              In new class declare enabledChanged() signal and rewrite setEnabled() member to emit that signal after calling setEnabled() from base class. Rest of the logic will be done by the base class.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nekkceb
                wrote on last edited by
                #7

                Looks like I've lost my case, I give up!

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

                  Out of curiosity, can you tell us your use case for that feature ? Since generally disabling a widget based on some condition is more of a relation between e.g. a button checked state than a button disabled state

                  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
                  • N Offline
                    N Offline
                    nekkceb
                    wrote on last edited by
                    #9

                    I was putting together a dialog with a lot of buttons, and several buttons become interdependent. I have not used checkable and checked() on QPushButtons, I dont think that is the behavior I want. I want to be able to make certain buttons inaccessible depending on certain events, not to push/unpush them. So far, the enabed(true/false) works well, setting enabled(false) grays out the button face and makes it unresponsive. If I change the checked state to true, the button looks like it is pressed, which would be confusing to the users. So when certain events happen, I do a check on all the buttons, with code that looks something like:
                    @
                    button1.setEnabled(<some condition>);
                    button2.setEnabled(button1.isEnabled())
                    .
                    .
                    .
                    etc
                    @

                    I still think it would be easier to connect button1 to button 2 with an enabledChanged event rather than this type of code, which is prone to errors.

                    Question to you: why is enabledChanged useful in a QGraphicsObject, but not in a button?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andreyc
                      wrote on last edited by
                      #10

                      [quote author="nekkceb" date="1397058014"]I want to be able to make certain buttons inaccessible depending on certain events, not to push/unpush them.[/quote]

                      This sounds like a good case for "State Machine":http://qt-project.org/doc/qt-5/statemachine-api.html

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

                        andreyc has a good point with the State Machine suggestion

                        To answer your last question: essentially different use cases

                        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
                        • N Offline
                          N Offline
                          nekkceb
                          wrote on last edited by
                          #12

                          I was not aware of the state machine classes, that actually should work in this case. Thanks to you both for the feedback.

                          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