Хочу реализовать при нажатии на label
изменение текста в другом label
, но при запуске кода ничего не происходит.
Код:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import QLabel, pyqtSignal
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(708, 520)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(150, 70, 321, 151))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(240, 270, 191, 71))
self.label_2.setObjectName("label_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 708, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Test label "))
self.label_2.setText(_translate("MainWindow", "TextLabel"))
class ClickedLabel(QLabel):
clicked = pyqtSignal()
def mouseReleaseEvent(self, e):
super().mouseReleaseEvent(e)
self.clicked.emit()
class Testwindow (QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.label = ClickedLabel('Label')
self.label.clicked.connect(self.hi)
def hi(self):
self.label_2.setText('Hello')
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Testwindow()
w.show()
sys.exit(app.exec_())