0
votes

I am designing an application using PyQt that will manage multiple instances of Selenium. Each instance has a QFrame with unique information and controls and can be tabbed through from the main window.

class Instance(QFrame):

    def __init__(self):
        super().__init__()
        self.username = "whatever"

        ...

        self.startButton = QPushButton('Start')
        self.startButton.clicked.connect(lambda: self.engineStart())

        self.exitButton = QPushButton('Exit')
        self.exitButton.clicked.connect(lambda: self.engineExit())

        ...

How it looks

Users should be able to create and delete instances at will.

Creating a tab is no problem. I have a "+" button set as the QTabWidget's cornerWidget. It is connected to a simple method to add the tab.

class App(QFrame):

    def __init__(self):

        ...

    def addNewTab(self):
        t = Instance()
        self.tabs.addTab(t, t.username)

The problem is, how can I use the "Exit" button from the "inside" Instance class to remove the tabs that are managed from the main window's "outside" class? I need some way to call removeTab()

1

1 Answers

0
votes

To do what you want you must create a slot in the main window, and connect it to the clicked signal of the button as shown below:

class App(QFrame):

    def __init__(self):
        ...
    def addNewTab(self):
        t = Instance()
        self.tabs.addTab(t, t.username)
        t.exitButton.clicked.connect(self.slot)

    def slot(self):
        self.tabs.removeTab(your_index)