2024-03-28 21:26:18 发布
网友
如何在QCalendarWidget的年中单击选项时触发鼠标单击事件。你知道吗
年度最佳(2012年), 我想用pyqt5打印一些文本 有人能帮忙吗。提前感谢/
第一件事是使用findChildren获取显示年份的QSpinBox,然后它将检测鼠标事件,但正如this solution指出的,这是不可能的,因此解决方法是检测焦点事件:
from PyQt5 import QtCore, QtWidgets class MainWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.calendar_widget = QtWidgets.QCalendarWidget() self.setCentralWidget(self.calendar_widget) self.year_spinbox = self.calendar_widget.findChild( QtWidgets.QSpinBox, "qt_calendar_yearedit" ) self.year_spinbox.installEventFilter(self) def eventFilter(self, obj, event): if obj is self.year_spinbox and event.type() == QtCore.QEvent.FocusIn: print(self.year_spinbox.value()) return super().eventFilter(obj, event) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_())
第一件事是使用findChildren获取显示年份的QSpinBox,然后它将检测鼠标事件,但正如this solution指出的,这是不可能的,因此解决方法是检测焦点事件:
相关问题 更多 >
编程相关推荐