QLineEdit에 내장 마우스 호버 신호가 없습니다.
그러나 event-filter을 설치하면 비슷한 것을 쉽게 달성 할 수 있습니다. 이 기술은 모든 유형의 위젯에서 작동하며, 사용자가해야 할 수도있는 유일한 일은 set mouse tracking입니다 (QLineEdit의 경우 기본적으로 켜져있는 것처럼 보이지만).
from PyQt4 import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.edit = QtGui.QLineEdit(self)
self.edit.installEventFilter(self)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.edit)
def eventFilter(self, source, event):
if source is self.edit:
if event.type() == QtCore.QEvent.MouseMove:
pos = event.globalPos()
print('pos: %d, %d' % (pos.x(), pos.y()))
elif event.type() == QtCore.QEvent.Enter:
print('ENTER')
elif event.type() == QtCore.QEvent.Leave:
print('LEAVE')
return QtGui.QWidget.eventFilter(self, source, event)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(500, 300, 300, 100)
window.show()
sys.exit(app.exec_())
감사를 ekhumoro :
아래의 데모 스크립트
는 다양한 마우스 이동 이벤트를 추적하는 방법을 보여줍니다. 그것은 완벽하게 작동합니다 :) –