【发布时间】:2016-01-27 20:25:57
【问题描述】:
我只是想知道如何使QLineEdit 可点击,因为我想在点击QLineEdit 时清除该行的文本。
【问题讨论】:
-
这是一件很简单的事情。如果您只需要清除行编辑,请在您的自定义类中重新实现
mousePressEvent或mouseReleaseEvent并清除文本。或者使用上面@Ian 给出的链接中的事件过滤器。
标签: python-3.x pyqt5
我只是想知道如何使QLineEdit 可点击,因为我想在点击QLineEdit 时清除该行的文本。
【问题讨论】:
mousePressEvent 或 mouseReleaseEvent 并清除文本。或者使用上面@Ian 给出的链接中的事件过滤器。
标签: python-3.x pyqt5
这是我的 2 美分...
定义:
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtSignal
class cQLineEdit(QLineEdit):
clicked= pyqtSignal()
def __init__(self,widget):
super().__init__(widget)
def mousePressEvent(self,QMouseEvent):
self.clicked.emit()
用法:
self.cLE = cQLineEdit(self)
self.cLE.setFixedWidth(20)
self.cLE.move(10,200)
self.cLE.clicked.connect(self.printText)
def printText(self):
print("Yop,+++")
希望这能有所帮助。
【讨论】:
尝试使用下面的代码使QLineEdit 可点击:
class ClickableLabel(QLabel):
clicked = pyqtSignal()
def __init__(self,name, widget):
super().__init__(name, widget)
def mousePressEvent(self, QMouseEvent):
self.clicked.emit()
【讨论】:
QLabel,而不是QLineEdit