Okay, so pretty much every tutorial/understandable-written-in-human-language-documentation is for PyQt4. But, PyQt5 changed how the whole 'connect button to a slot' works, and I still can't figure it out how to do it.
I did a quick gui in QtDesigner, and I have a QPushButton and a label. When I click the button, I want the text on the label to change. in C++ in QtDesigner, It's easy to connect the two. But I have to write it all in python.
I convert .ui file with pyuic5 to .py file. There, in Ui_MainWindow class, I can see setupUi method, that initializes self.button as follows
self.testButton = QtWidgets.QPushButton(self.centralWidget)
self.testButton.setObjectName("newGame")
then, at the end of the method,
QtCore.QMetaObject.connectSlotsByName(MainWindow)
is called, but, to be honest, I can't figure out what it does and what it connects to where.
in Main class, inheriting from QMainWindow, i write a following method
@pyqtSlot(name='change')
def change_text(self):
self.ui.testLabel.setText("Button Clicked!")
And i can't figure out how to connect the button signal to that slot. In pyqt4 I could set it up manually by doing button.clicked.connect(self.change_text), but as I've found out, PyQt5 obsoleted and discarded such simple set-up.
Please, can anybody help me with that one?