Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Set up Widgets in current tab lose layout and visibility?
Forum Updated to NodeBB v4.3 + New Features

Set up Widgets in current tab lose layout and visibility?

Scheduled Pinned Locked Moved Unsolved Qt for Python
12 Posts 2 Posters 2.0k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    You are doing something pretty unusual here

            for i in range(4):
                ret_tab = getattr(self.main_ui, "retTabWidget_a{}".format(i))
                self.ret_ui.setupUi(ret_tab.widget(0), i, 1)
    

    The canonical way to use designer based widgets is to generate the code and build one widget which will contain the setupUi call and usually some custom stuff. Then you reuse that widget further in your project.

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

    C 1 Reply Last reply
    1
    • SGaistS SGaist

      Hi and welcome to devnet,

      You are doing something pretty unusual here

              for i in range(4):
                  ret_tab = getattr(self.main_ui, "retTabWidget_a{}".format(i))
                  self.ret_ui.setupUi(ret_tab.widget(0), i, 1)
      

      The canonical way to use designer based widgets is to generate the code and build one widget which will contain the setupUi call and usually some custom stuff. Then you reuse that widget further in your project.

      C Offline
      C Offline
      CAJJED
      wrote on last edited by
      #3

      @SGaist , thanks of the response. In the big picture all I want to do is be able to duplicate the widgets into each tab. There will of course be more tabs added and others deleted but each tab will have the same widgets, thus my take to give them all different names so I could easily update them (a1r1, a2r1, a1r2, etc). I did initially just use the default Ui class created from QT Designer but it had the same issues so I was initially thinking it had something to do with the tabs having the same object names.

      Can you elaborate on your suggestion? I currently have a main ui and then this widget ui (ret_ui). The tabs are in the main ui already so I just grab them and then put the widgets in. But I am sensing from your answer that there is a much better method of doing this?

      SGaistS 1 Reply Last reply
      0
      • C CAJJED

        @SGaist , thanks of the response. In the big picture all I want to do is be able to duplicate the widgets into each tab. There will of course be more tabs added and others deleted but each tab will have the same widgets, thus my take to give them all different names so I could easily update them (a1r1, a2r1, a1r2, etc). I did initially just use the default Ui class created from QT Designer but it had the same issues so I was initially thinking it had something to do with the tabs having the same object names.

        Can you elaborate on your suggestion? I currently have a main ui and then this widget ui (ret_ui). The tabs are in the main ui already so I just grab them and then put the widgets in. But I am sensing from your answer that there is a much better method of doing this?

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        There's not much more to it than what I wrote before: you should have one widget per designer generated one. Then use that widget for the rest of the design.

        You can take a look at the C++ examples, it might be clearer from them.

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

        C 1 Reply Last reply
        0
        • SGaistS SGaist

          There's not much more to it than what I wrote before: you should have one widget per designer generated one. Then use that widget for the rest of the design.

          You can take a look at the C++ examples, it might be clearer from them.

          C Offline
          C Offline
          CAJJED
          wrote on last edited by
          #5

          @SGaist thanks again.

          There is something subtle that you are saying that I am missing because I think that is what I have (removing the custom object name stuff). I created a form widget in QT Designer that has a bunch of widgets in it. I then add that form widget each time I create a new tab.

          Are you just saying don't customize the setupUi? Which I totally get now and will not do.

          SGaistS 1 Reply Last reply
          0
          • C CAJJED

            @SGaist thanks again.

            There is something subtle that you are saying that I am missing because I think that is what I have (removing the custom object name stuff). I created a form widget in QT Designer that has a bunch of widgets in it. I then add that form widget each time I create a new tab.

            Are you just saying don't customize the setupUi? Which I totally get now and will not do.

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @CAJJED you are calling setupUi from the same object repeatedly which is not the same thing as it being part of the construction of the widget.

            Check this tutorial, the code sample in the Putting everything together part shows what I have in mind.

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

            C 1 Reply Last reply
            1
            • SGaistS SGaist

              @CAJJED you are calling setupUi from the same object repeatedly which is not the same thing as it being part of the construction of the widget.

              Check this tutorial, the code sample in the Putting everything together part shows what I have in mind.

              C Offline
              C Offline
              CAJJED
              wrote on last edited by
              #7

              @SGaist, I sense a light bulb is just waiting to go off for me so I appreciate your time. The example you share there is a main UI and then a dialog UI. In the example you setup the main UI and then when a button or other action occurs you load the dialog UI. I feel like I am doing the same thing. I start with a main UI which is just some empty QTabWidgets and such. Then when instructed via serial connection I will add my tab widget (using setupUI or loadUI or whatever the class function name. I am just not seeing the difference?

              SGaistS 1 Reply Last reply
              0
              • C CAJJED

                @SGaist, I sense a light bulb is just waiting to go off for me so I appreciate your time. The example you share there is a main UI and then a dialog UI. In the example you setup the main UI and then when a button or other action occurs you load the dialog UI. I feel like I am doing the same thing. I start with a main UI which is just some empty QTabWidgets and such. Then when instructed via serial connection I will add my tab widget (using setupUI or loadUI or whatever the class function name. I am just not seeing the difference?

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8
                class RETWidget(QWidget, Ui_RET):
                    def __init__(self, parent=None):
                        super().__init__(parent)
                        self.setupUi(self)
                

                Then when you want to add your widget to a QTabWidget

                ret_widget = RETWidget()
                tab_widget.addWidget(ret_widget, self.tr("some text"))
                

                By the way, why do you have 4 QTabWidget in your design where you put one widget per tab widget ? It kinds of defeat the purpose.

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

                C 1 Reply Last reply
                0
                • SGaistS SGaist
                  class RETWidget(QWidget, Ui_RET):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setupUi(self)
                  

                  Then when you want to add your widget to a QTabWidget

                  ret_widget = RETWidget()
                  tab_widget.addWidget(ret_widget, self.tr("some text"))
                  

                  By the way, why do you have 4 QTabWidget in your design where you put one widget per tab widget ? It kinds of defeat the purpose.

                  C Offline
                  C Offline
                  CAJJED
                  wrote on last edited by
                  #9

                  @SGaist thanks for the simple example, it is appreciated.

                  In this code I have a main QTabWidget (the one with 4) and then in each of those I will have 0 - 5 Tabs in the sub Widget (the main tabs will never change). The sub tabs are what will be added/removed as the program runs.

                  Very open to ideas/suggestions that will make this cleaner?

                  SGaistS 1 Reply Last reply
                  0
                  • C CAJJED

                    @SGaist thanks for the simple example, it is appreciated.

                    In this code I have a main QTabWidget (the one with 4) and then in each of those I will have 0 - 5 Tabs in the sub Widget (the main tabs will never change). The sub tabs are what will be added/removed as the program runs.

                    Very open to ideas/suggestions that will make this cleaner?

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @CAJJED don't use multiple layers of tab bars. It's really not a nice way to present your UI (remember Word's configuration with several rows of tab widget ?)

                    One possible way is to follow Qt Creator's preferences. Have a QListView/Widget to change topic and beside it, a widget that will then contain the QTabWidget.

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

                    C 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      @CAJJED don't use multiple layers of tab bars. It's really not a nice way to present your UI (remember Word's configuration with several rows of tab widget ?)

                      One possible way is to follow Qt Creator's preferences. Have a QListView/Widget to change topic and beside it, a widget that will then contain the QTabWidget.

                      C Offline
                      C Offline
                      CAJJED
                      wrote on last edited by
                      #11

                      @SGaist thanks for the guidance,

                      We engineers like big ugly monstrosity displays ;-)

                      I think I follow what you are saying. You end up with just a single QTabWidget with all the tabs and then you just your QListView to select the visible tab widget?

                      List View:
                      Main 1
                      Tab 1
                      Tab 2
                      Main 2
                      Tab 1
                      Tab 2
                      Tab 3

                      Then you would have your 5 tabs widgets.

                      The other way to interpret would be to just have a single widget and just modify the contents each time the list view selection changes?

                      SGaistS 1 Reply Last reply
                      0
                      • C CAJJED

                        @SGaist thanks for the guidance,

                        We engineers like big ugly monstrosity displays ;-)

                        I think I follow what you are saying. You end up with just a single QTabWidget with all the tabs and then you just your QListView to select the visible tab widget?

                        List View:
                        Main 1
                        Tab 1
                        Tab 2
                        Main 2
                        Tab 1
                        Tab 2
                        Tab 3

                        Then you would have your 5 tabs widgets.

                        The other way to interpret would be to just have a single widget and just modify the contents each time the list view selection changes?

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @CAJJED said in Set up Widgets in current tab lose layout and visibility?:

                        @SGaist thanks for the guidance,

                        We engineers like big ugly monstrosity displays ;-)

                        As an engineer, I have to vehemently disagree with that statement ;-)

                        QListView + QStackedWidget
                        Your QListView then drives the current widget shown from the QStackedWidget.
                        Then you add as many QTabWidget you need to the QStackedWidget. This will be simpler and cleaner to manage.

                        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

                        • Login

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