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. QWidget, setEnable, change not visible immediately
Forum Updated to NodeBB v4.3 + New Features

QWidget, setEnable, change not visible immediately

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.4k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    In my application I have logic that enables or disables buttons based on conditions, I emit a signal to notify the button to change state and using the debugger I can see that when the signal is emitted the slot is called and the setEnabled function called.

    If the application is left to run the visible appearance of the button does not change to reflect the state change, however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state.

    What could be the cause of this and how should I fix it, this is the slot that enable and disables the button:

    void clsXMLnode::APIstate(bool blnState) {
        QWidget* pobjWidget(pobjGetWidget());    
        if ( pobjWidget == nullptr ) {
        //No widget, do nothing
            return;
        }
        pobjWidget->setEnabled(blnState);
    }
    

    Kind Regards,
    Sy

    J.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @SPlatten said in QWidget, setEnable, change not visible immediately:

      Could it be that I need to change the connection type as presently its using the default ?

      it shouldn't make a difference, or is this somehow across threads ?

      try calling update() or repaint() on the button widget, after changing the enabled state.

      It should do that automatically but, see if that helps!

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #9

      @J-Hilk , sorry for wasting your time....I've found the problem which as an error in my code.

      Kind Regards,
      Sy

      1 Reply Last reply
      1
      • SPlattenS SPlatten

        In my application I have logic that enables or disables buttons based on conditions, I emit a signal to notify the button to change state and using the debugger I can see that when the signal is emitted the slot is called and the setEnabled function called.

        If the application is left to run the visible appearance of the button does not change to reflect the state change, however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state.

        What could be the cause of this and how should I fix it, this is the slot that enable and disables the button:

        void clsXMLnode::APIstate(bool blnState) {
            QWidget* pobjWidget(pobjGetWidget());    
            if ( pobjWidget == nullptr ) {
            //No widget, do nothing
                return;
            }
            pobjWidget->setEnabled(blnState);
        }
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @SPlatten there may be some typos or mistakes in this:

        however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state

        but I'm unable to decipher what is actually happening. Can you elaborate more?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        SPlattenS 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @SPlatten there may be some typos or mistakes in this:

          however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state

          but I'm unable to decipher what is actually happening. Can you elaborate more?

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @J-Hilk , A window is displayed with widgets, I have a number of buttons at the bottom of the window, the state of these buttons is defined by editing the widgets.

          If a QLineEdit widget is modified then one of the buttons at the bottom is enabled by emitting a signal. As stated in my post I can see that the slot is called and the correct widget ( button ) is being set to the correct state which is passed into the slot.

          The problem is that the button's visible state does not change from disabled to enabled unless I change the window focus to another window, then the button visible state changes.

          Kind Regards,
          Sy

          J.HilkJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @J-Hilk , A window is displayed with widgets, I have a number of buttons at the bottom of the window, the state of these buttons is defined by editing the widgets.

            If a QLineEdit widget is modified then one of the buttons at the bottom is enabled by emitting a signal. As stated in my post I can see that the slot is called and the correct widget ( button ) is being set to the correct state which is passed into the slot.

            The problem is that the button's visible state does not change from disabled to enabled unless I change the window focus to another window, then the button visible state changes.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @SPlatten alright

            what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            SPlattenS 3 Replies Last reply
            0
            • J.HilkJ J.Hilk

              @SPlatten alright

              what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #5

              @J-Hilk Qt 5.15.2, no custom style sheets. The buttons are based on QPushButton:

                  class clsQtPushBtn : public QPushButton, public clsXMLinterface {
                  Q_OBJECT
                  private:
                      static mpSignals mscmpSignals;
              
                      QMetaObject::Connection connect(clsSignal* pobjSignal);
              
                  private slots:
                      void rptrClicked(bool blnChecked);
                      void rptrPressed();
                      void rptrReleased();
                      void rptrToggled(bool blnChecked);
              
                  public:
                      static const char mscszQtSignalClicked[];
                      static const char mscszQtSignalPressed[];
                      static const char mscszQtSignalReleased[];
                      static const char mscszQtSignalToggled[];
                      static const char mscszStyleBorderBottomLeftRadius[];
                      static const char mscszStyleBorderBottomRightRadius[];
                      static const char mscszStyleBorderTopLeftRadius[];
                      static const char mscszStyleBorderTopRightRadius[];
              
                      explicit clsQtPushBtn(clsXMLnode* pobjNode, QString* pstrCSS
                                                                , QWidget* parent = nullptr);
                      static bool blnValidSignal(QString strSignal);
                      static mpSignals* pmpGetSignals() { return &clsQtPushBtn::mscmpSignals; }
              
                  signals:
              
                  public slots:
                  };
              

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @SPlatten alright

                what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #6

                @J-Hilk Could it be that I need to change the connection type as presently its using the default ?

                        QObject::connect(pobjWindow, &clsXMLnode::APInotifyUndoChanges
                                        ,pobjNode, &clsXMLnode::APIstate);
                

                Kind Regards,
                Sy

                J.HilkJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @J-Hilk Could it be that I need to change the connection type as presently its using the default ?

                          QObject::connect(pobjWindow, &clsXMLnode::APInotifyUndoChanges
                                          ,pobjNode, &clsXMLnode::APIstate);
                  
                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #7

                  @SPlatten said in QWidget, setEnable, change not visible immediately:

                  Could it be that I need to change the connection type as presently its using the default ?

                  it shouldn't make a difference, or is this somehow across threads ?

                  try calling update() or repaint() on the button widget, after changing the enabled state.

                  It should do that automatically but, see if that helps!


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  SPlattenS 1 Reply Last reply
                  1
                  • J.HilkJ J.Hilk

                    @SPlatten alright

                    what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #8

                    @J-Hilk , looking at this again in the debugger, I can now see that the slot is not actually being called until I change the focus, yet the signal is being emitted instantly.

                    Does that help shed any light on why the slot isn't being called when the signal is emitted ?

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @SPlatten said in QWidget, setEnable, change not visible immediately:

                      Could it be that I need to change the connection type as presently its using the default ?

                      it shouldn't make a difference, or is this somehow across threads ?

                      try calling update() or repaint() on the button widget, after changing the enabled state.

                      It should do that automatically but, see if that helps!

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #9

                      @J-Hilk , sorry for wasting your time....I've found the problem which as an error in my code.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      1

                      • Login

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