PYQT의 QT 위젯에서 내려온 위젯에서 모든 마우스 이벤트를 어떻게 캡처하려면?
문제
특히 QcalendarWidget에서 상속을 받고 있으며 Mousepressevent 메소드를 무시하고 날짜를 선택할 수있는 날짜를 필터링하고 싶습니다 (간단한 범위가 아닌 Disjoint Set). 그러나이 방법을 무시할 때 캘린더 내부의 자식 위젯으로가는 이벤트를 포착하지 않습니다. 어떻게 할 수 있습니까?
해결책
Mousepressevent를 무시하는 것이 qcalendarwidget에서 효과가 없다는 것에 놀랐습니다. 대부분의 다른 위젯에서 작동합니다. QcalendarWidget의 문서를 살펴본 후 클릭 된 신호가 있음을 알 수 있습니다. 연결하면 작동합니다.
import sys
from PyQt4 import QtGui, QtCore
class MyCalendar(QtGui.QCalendarWidget):
def __init__(self):
QtGui.QCalendarWidget.__init__(self)
self.connect(self, QtCore.SIGNAL("clicked(QDate)"), self.on_click)
self.prev_date = self.selectedDate()
def on_click(self, date):
if self.should_ignore(date):
self.setSelectedDate(self.prev_date)
return
self.prev_date = date
def should_ignore(self, date):
""" Do whatever here """
return date.day() > 15
app = QtGui.QApplication(sys.argv)
cal = MyCalendar()
cal.show()
app.exec_()
나는 전에 qcalendarwidget을 확인한 적이 없습니다. 꽤 달콤한 작은 위젯.
제휴하지 않습니다 StackOverflow