如何在默认情况下QLineEdit
无效,但在收到mouseDoubleClickEvent()
时会启用?
如何实施mouseDoubleClickEvent()
?
我总是得到错误"没有足够的论据"当我尝试类似的东西时:
if self.MyQLineEdit.mouseDoubleClickEvent() == True:
do something
答案 0 :(得分:1)
您无法使用以下语句设置该事件:
if self.MyQLineEdit.mouseDoubleClickEvent () == True:
有两种可能的选择:
QLineEdit
:import sys
from PyQt4 import QtGui
class LineEdit(QtGui.QLineEdit):
def mouseDoubleClickEvent(self, event):
print("pos: ", event.pos())
# do something
class Widget(QtGui.QWidget):
def __init__(self, *args, **kwargs):
QtGui.QWidget.__init__(self, *args, **kwargs)
le = LineEdit()
lay = QtGui.QVBoxLayout(self)
lay.addWidget(le)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
import sys
from PyQt4 import QtGui, QtCore
class Widget(QtGui.QWidget):
def __init__(self, *args, **kwargs):
QtGui.QWidget.__init__(self, *args, **kwargs)
self.le = QtGui.QLineEdit()
lay = QtGui.QVBoxLayout(self)
lay.addWidget(self.le)
self.le.installEventFilter(self)
def eventFilter(self, watched, event):
if watched == self.le and event.type() == QtCore.QEvent.MouseButtonDblClick:
print("pos: ", event.pos())
# do something
return QtGui.QWidget.eventFilter(self, watched, event)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())