QLineEdit在PyQt5中没有对象属性'clicked'?

QLineEdit has no object attribute 'clicked' in PyQt5?

在 PyQt5 中,我希望你添加一个功能,当我单击 QLineEdit 框时,按钮变成黄色,而之前是白色的。当点击 'SET' 按钮时,它又变黑了。

但问题是 QEditLine 没有点击功能。

当我 运行 下面的代码给出错误 QLineEdit 没有对象属性 'clicked'

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys

class mylineedit(QLineEdit):
  clicked=pyqtSignal()  # Definition clicked Signal
  def mouseReleaseEvent(self, QMouseEvent):
    if QMouseEvent.button()==Qt.LeftButton:
      self.clicked.emit()

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Hatchery System")
        self.resize(1064, 665)
        self.setStyleSheet("background-color: white")
        self.setFixedWidth(700)
        self.setFixedHeight(500)

        self.button_5 = QPushButton('', self)
        self.button_5.setGeometry(QtCore.QRect(350, 50, 61, 71))
        self.button_5.setStyleSheet("background-color: red;")
        self.button_5.setIcon(QIcon('/home/lenovo/PycharmProjects/test/images/bulb_black.svg'))
        self.button_5.setCheckable(True)
        self.button_5.setIconSize(QtCore.QSize(32, 32))
        self.button_5.clicked.connect(self.button_bulb_clicked)

        self.line = QtWidgets.QLineEdit(self)
        self.line.setGeometry(QtCore.QRect(200, 150, 260, 161))
        self.line.setStyleSheet("color: rgb(239, 41, 41);" "Font: Italic;")
        self.line.setText("33.3")
        self.line.setFont(QFont("Ani", 100))
        self.line.clicked.connect(self.button_bulb_clicked)
        # self.clicked.connect(self.button_bulb_clicked())

        self.button = QPushButton('', self)
        self.button.setGeometry(QtCore.QRect(500, 230, 61, 71))
        self.button.setText("SET")
        self.button.setCheckable(True)
        self.button.setIconSize(QtCore.QSize(32, 32))

    def button_bulb_clicked(self):
        if self.line.isChecked():
            self.button_5.setIcon(QIcon('/home/lenovo/PycharmProjects/test/images/bulb_yellow.svg'))
        else:
            self.button_5.setIcon(QIcon('/home/lenovo/PycharmProjects/test/images/bulb_black.svg'))
            self.button_5.setIconSize(QtCore.QSize(32, 32))

app = QApplication([])
mw = MainWindow()
mw.show()
app.exec_()

输出:

QLineEdit 没有 isChecked()clicked 但您可以使用 QCheckBox()

self.line = QtWidgets.QCheckBox(self)

from PyQt5.QtWidgets import QLineEdit, QApplication, QWidget



class main(QWidget):
    def __init__(self):
        super().__init__()


        self.lineEdit = QLineEdit(self)
        self.lineEdit.setPlaceholderText("Click Please")

        self.lineEdit.mousePressEvent = self.clickLine

        self.resize(200,100)
        self.show()  


    def clickLine(self, mouseEvent):
        self.lineEdit.setPlaceholderText("Thanks Man :)")


App = QApplication([])
window = main()
App.exec()