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. Generic way to restore / set widgets to initial state ?
Forum Updated to NodeBB v4.3 + New Features

Generic way to restore / set widgets to initial state ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 1.6k Views 2 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 27 Jan 2022, 12:25 last edited by
    #1

    Is there a generic signal or function to set a widget to its initial state? I have a form that when loaded for the first time the state of the widgets have defaults, after interacting with the widgets the defaults are no more.

    I have a QListWidget that I can use to select a context that effects the content of other widgets, what I really want to do is when the itemSelectionChanged signal occurs I would like to ensure all the widgets are in a known state.

    Kind Regards,
    Sy

    J J 2 Replies Last reply 27 Jan 2022, 12:29
    0
    • S Offline
      S Offline
      SPlatten
      wrote on 27 Jan 2022, 15:11 last edited by
      #9

      @JonB , @J-Hilk , the dialog isn't being closed so the controls won't be deleted or recreated, the change in the QListWidget causes the controls to be updated live.

      Having given this some thought I'm going to implement a signal, something like dataUpdate where the controls will connect to this signal and they're own slot will update the control.

      Kind Regards,
      Sy

      P 1 Reply Last reply 27 Jan 2022, 15:21
      0
      • S SPlatten
        27 Jan 2022, 12:25

        Is there a generic signal or function to set a widget to its initial state? I have a form that when loaded for the first time the state of the widgets have defaults, after interacting with the widgets the defaults are no more.

        I have a QListWidget that I can use to select a context that effects the content of other widgets, what I really want to do is when the itemSelectionChanged signal occurs I would like to ensure all the widgets are in a known state.

        J Online
        J Online
        jsulm
        Lifetime Qt Champion
        wrote on 27 Jan 2022, 12:29 last edited by jsulm
        #2

        @SPlatten What is not clear: does this state have to be persistent? And what would this state be exactly?
        For persistant states you can use QSettings.

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

        S 1 Reply Last reply 27 Jan 2022, 12:32
        1
        • J jsulm
          27 Jan 2022, 12:29

          @SPlatten What is not clear: does this state have to be persistent? And what would this state be exactly?
          For persistant states you can use QSettings.

          S Offline
          S Offline
          SPlatten
          wrote on 27 Jan 2022, 12:32 last edited by SPlatten
          #3

          @jsulm , I'm using property and setProperty to track the state of the widgets. I will investigate QSettings. I have reset signals that are emitted what the list selection changes, this sets the properties to {}. However the initial states of the widgets isn't being reset.

          I think I'm going to have the same problem, presently I have a checkbox that initially isn't set, I change to a selection where the checkbox is set...this is ok, because the initial state was Unchecked then the new state changes to Checked, if I change the selection to another entry where the checkbox is also checked, that's where I get the problem because although the property is reset the widget isn't so when clicking the checkbox the new state is unchecked which because the property was reset becomes the new initial setting.

          [Edit], I don't think QSettings is going to help, as it seems another way of doing exactly what I'm doing with property and setProperty, its the widgets I need to manage.

          Kind Regards,
          Sy

          P J 2 Replies Last reply 27 Jan 2022, 12:59
          0
          • S SPlatten
            27 Jan 2022, 12:32

            @jsulm , I'm using property and setProperty to track the state of the widgets. I will investigate QSettings. I have reset signals that are emitted what the list selection changes, this sets the properties to {}. However the initial states of the widgets isn't being reset.

            I think I'm going to have the same problem, presently I have a checkbox that initially isn't set, I change to a selection where the checkbox is set...this is ok, because the initial state was Unchecked then the new state changes to Checked, if I change the selection to another entry where the checkbox is also checked, that's where I get the problem because although the property is reset the widget isn't so when clicking the checkbox the new state is unchecked which because the property was reset becomes the new initial setting.

            [Edit], I don't think QSettings is going to help, as it seems another way of doing exactly what I'm doing with property and setProperty, its the widgets I need to manage.

            P Offline
            P Offline
            Pl45m4
            wrote on 27 Jan 2022, 12:59 last edited by
            #4

            @SPlatten

            I believe there is nothing like an "initial state" based on your definition.
            A QCheckBox for example is always unchecked. Even when you set the tick in QtDesigner, the checkbox is unchecked but during moc in your compiled C-header, it sets the properties from your ui-file, for example, and enables/checks the QCheckBox.

            So you have to decide what you define as "initial state" and how/where do you save it and track it.

            QSettings could be an option... your reset signal could set the stored settings again ( -> "reset")


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            1
            • S SPlatten
              27 Jan 2022, 12:32

              @jsulm , I'm using property and setProperty to track the state of the widgets. I will investigate QSettings. I have reset signals that are emitted what the list selection changes, this sets the properties to {}. However the initial states of the widgets isn't being reset.

              I think I'm going to have the same problem, presently I have a checkbox that initially isn't set, I change to a selection where the checkbox is set...this is ok, because the initial state was Unchecked then the new state changes to Checked, if I change the selection to another entry where the checkbox is also checked, that's where I get the problem because although the property is reset the widget isn't so when clicking the checkbox the new state is unchecked which because the property was reset becomes the new initial setting.

              [Edit], I don't think QSettings is going to help, as it seems another way of doing exactly what I'm doing with property and setProperty, its the widgets I need to manage.

              J Offline
              J Offline
              JonB
              wrote on 27 Jan 2022, 13:03 last edited by JonB
              #5

              @SPlatten
              QSettings isn't really the right tool for widget saving settings (well, IMHO, though if it suits you could, it's just one way of saving certain information in particular format, just like JSON). You cannot serialize, deserialize or "reset" (whatever that might mean) widgets.

              Really you just need to write explicit code. If by any chance you have a complicated widget state to reset, and you designed it in Designer, QUiLoader might suit you in certain specific circumstances.

              1 Reply Last reply
              0
              • S SPlatten
                27 Jan 2022, 12:25

                Is there a generic signal or function to set a widget to its initial state? I have a form that when loaded for the first time the state of the widgets have defaults, after interacting with the widgets the defaults are no more.

                I have a QListWidget that I can use to select a context that effects the content of other widgets, what I really want to do is when the itemSelectionChanged signal occurs I would like to ensure all the widgets are in a known state.

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 27 Jan 2022, 13:06 last edited by
                #6

                @SPlatten usually if you want to restore / set widgets to its initial state you would do:

                /*delete*/ m_widget->deleteLater();
                m_widget = new MyWidget();
                

                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.

                J 1 Reply Last reply 27 Jan 2022, 13:07
                2
                • J J.Hilk
                  27 Jan 2022, 13:06

                  @SPlatten usually if you want to restore / set widgets to its initial state you would do:

                  /*delete*/ m_widget->deleteLater();
                  m_widget = new MyWidget();
                  
                  J Offline
                  J Offline
                  JonB
                  wrote on 27 Jan 2022, 13:07 last edited by
                  #7

                  @J-Hilk
                  Yes, but the OP should be aware that would kill any/all signals/slots on the original, any references to it, its location/parentage, etc.

                  J 1 Reply Last reply 27 Jan 2022, 13:10
                  1
                  • J JonB
                    27 Jan 2022, 13:07

                    @J-Hilk
                    Yes, but the OP should be aware that would kill any/all signals/slots on the original, any references to it, its location/parentage, etc.

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 27 Jan 2022, 13:10 last edited by
                    #8

                    @JonB

                    yes, thats implied! The initial stat => just after creation/allocation :P


                    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.

                    1 Reply Last reply
                    2
                    • S Offline
                      S Offline
                      SPlatten
                      wrote on 27 Jan 2022, 15:11 last edited by
                      #9

                      @JonB , @J-Hilk , the dialog isn't being closed so the controls won't be deleted or recreated, the change in the QListWidget causes the controls to be updated live.

                      Having given this some thought I'm going to implement a signal, something like dataUpdate where the controls will connect to this signal and they're own slot will update the control.

                      Kind Regards,
                      Sy

                      P 1 Reply Last reply 27 Jan 2022, 15:21
                      0
                      • S SPlatten
                        27 Jan 2022, 15:11

                        @JonB , @J-Hilk , the dialog isn't being closed so the controls won't be deleted or recreated, the change in the QListWidget causes the controls to be updated live.

                        Having given this some thought I'm going to implement a signal, something like dataUpdate where the controls will connect to this signal and they're own slot will update the control.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 27 Jan 2022, 15:21 last edited by Pl45m4
                        #10

                        @SPlatten said in Generic way to restore / set widgets to initial state ?:

                        thought I'm going to implement a signal, something like dataUpdate where the controls will connect to this signal and they're own slot will update the control.

                        Just do it :)

                        You know best, how your widgets should look in your initial state or how to "reset" them. Can't be that hard to think about everything you want to undo / reset and then write a function which does so. Some function or slot which can be connected to your signal and which will clear, uncheck, flush, whatever... everything.

                        Btw: This behavior is not very uncommon. A dialog with some input fields and a button to "clear" / reset all input, while keeping the rest. On QLineEdits you can simply call clear() (you probably know that)... for every other widget and maybe even custom ones, we can't help you, how your initial state might look like and how to get there :)


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        0

                        1/10

                        27 Jan 2022, 12:25

                        • Login

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