Set up Widgets in current tab lose layout and visibility?
-
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.
-
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.
@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?
-
@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?
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.
-
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.
@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.
-
@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.
-
@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?
-
@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?
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.
-
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.
@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?
-
@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?
@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.
-
@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.
@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 3Then 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?
-
@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 3Then 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?
@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.