DerJFK
DerJFK

Reputation: 321

PyQt5 QPushbutton with additional parameters

I have one TabWidget and want to add some tabs by clicking on a button. But it should work like

click Button "a" -> add Tab with title "a" and a special widget
click Button "b" -> add Tab with title "b" and a special widget

If I comment out the line with the slot of the button, all is working well. Also if I remove the parameter from the slot, it also gives no error message.

But with the code below I got:

" argument 1 has unexpected type 'NoneType' "

Is it wrong to add the parameter to the slot, like I did?

Thanks for your answers

class MainWindow(QtWidgets.QMainWindow):

    def __init__(self):
      QtWidgets.QMainWindow.__init__(self)
      self.ui= uic.loadUi('GUI/mainWindow.ui',self)

      self.ui.tabWidget.setMovable(True)
      self.ui.tabWidget.clear()

      #Slots
      self.ui.btn_lief.clicked.connect(self.addTab(Lieferschein(),'Lieferschein'))

    def addTab(self,widget : 'QWidget',name : str):
      idx = self.ui.tabWidget.currentIndex()+1
      self.ui.tabWidget.insertTab(idx,widget,name)
      self.ui.tabWidget.setCurrentIndex(idx)

Upvotes: 1

Views: 269

Answers (1)

DerJFK
DerJFK

Reputation: 321

I found the following Link. It works if I use:

self.ui.btn_lief.clicked.connect(self.addTab(lambda: Lieferschein(),'Lieferschein'))

Upvotes: 1

Related Questions