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()

    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.

  • Lifetime Qt Champion


    You are printing the result of the creation of a new InterfaceTemplateDialog. What's your point in doing that ?

  • Hello,

    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()

    and run_btn_start() will be implemented in InterfaceTemplateDialog

    Getting the same reference for different tabs make me doubt about a strange problem.

  • Hello again,

    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.

  • Lifetime Qt Champion

    That's pretty convoluted.

    You seem to be creating InterfaceTemplateDialog for each tab in your QTabWidget and then in your onChange method you seem to create a new InterfaceTemplateDialog to 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 .

  • Lifetime Qt Champion

    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 ?

  • Hello,

    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.

  • Moderators

    @EJWA If the table is too big how can tab widget help?
    You should put your table into QScrollArea

  • Hi, this is what my client want. I think tabs are more beautiful in design than tables.

  • Lifetime Qt Champion

    What kind of table ? Showing what ?

  • Table with different scenarios (use cases) : every column has many checkboxes to check to run the program selected

  • Lifetime Qt Champion

    Then why don't you put the active logic directly in your InterfaceTemplateDialog ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.