Similar reference for different tabs in tabwidget (Strange problem )
I am creating tabs dynamically in a tabwidget using this method :
def add_new_tab(self,index,text): self.new_tab = InterfaceTemplateDialog() self.tabs.addTab(self.new_tab,text) self.tabs.setTabText(index,text)
Trying to print the reference of selected tab using this method :
def onChange(self): currentIndex = self.tabs.currentIndex() print InterfaceTemplateDialog()
I get the same reference for every selected tab except for the first selected:
<OptionsTRANUS.interface_template.InterfaceTemplateDialog object at 0x0000000014F842F0> <OptionsTRANUS.interface_template.InterfaceTemplateDialog object at 0x0000000014F8EE18> <OptionsTRANUS.interface_template.InterfaceTemplateDialog object at 0x0000000014F8EE18> <OptionsTRANUS.interface_template.InterfaceTemplateDialog object at 0x0000000014F8EE18> <OptionsTRANUS.interface_template.InterfaceTemplateDialog object at 0x0000000014F8EE18>
If references are similar, I cannot control actions on tabs.
So what is this strange problem ?
Thank you in advance for your help.
You are printing the result of the creation of a new InterfaceTemplateDialog. What's your point in doing that ?
I want to add an attribute in my class InterfaceTemplateDialog which is index so I can after perform actions on every tab by his index. Example :
currentIndex = self.tabs.currentIndex() InterfaceTemplateDialog(currentIndex).run_btn_start()
and run_btn_start() will be implemented in InterfaceTemplateDialog
Getting the same reference for different tabs make me doubt about a strange problem.
I think the correct way to get the correct reference is to use :
currentTabWidget = self.tabs.currentWidget()
with self.tabs = self.findChild(QtGui.QTabWidget, 'tabWidget')
I tested, it works well. Thanks.
That's pretty convoluted.
You seem to be creating
InterfaceTemplateDialogfor each tab in your QTabWidget and then in your
onChangemethod you seem to create a new
InterfaceTemplateDialogto call a function on it. That doesn't make much sense.
What exactly do you want to do ? And when ?
My tabs have the same content (widget) with same buttons, checkboxes, .. What I want to do exactly is to execute actions (button click ..) on a selectioned tab .
Then create your widget, then the connections for that widget and finally add it to your QTabWidget.
However, why do you need a QTabWidget that contains the exact same widget several times ?
Actually, there is a table with serveral columns. Now, we want to transform this table to a tabwidget beacause, may be we can have many columns so the size of the table will be not sufficient.
@EJWA If the table is too big how can tab widget help?
You should put your table into QScrollArea http://doc.qt.io/qt-5.8/qscrollarea.html
Hi, this is what my client want. I think tabs are more beautiful in design than tables.
What kind of table ? Showing what ?
Table with different scenarios (use cases) : every column has many checkboxes to check to run the program selected
Then why don't you put the active logic directly in your InterfaceTemplateDialog ?