我正在尝试使用 Pyqt5 QDateEdit 构建日期打印机。我可以弹出日历,但我想在控制台(或窗口中的标签)中写入单击日期的字符串。我试过了print(self.calendarWidget().document().toPlainText())
,print(self.calendarWidget().currentText())
但是没有用。
我使用此代码;
from PyQt5 import QtCore, QtWidgets
class DateEdit(QtWidgets.QDateEdit):
popupSignal = QtCore.pyqtSignal()
def __init__(self, parent=None):
super(DateEdit, self).__init__(parent)
self.setCalendarPopup(True)
self.calendarWidget().installEventFilter(self)
def eventFilter(self, obj, event):
if self.calendarWidget() is obj and event.type() == QtCore.QEvent.Show:
self.popupSignal.emit()
return super(DateEdit, self).eventFilter(obj, event)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = DateEdit()
w.popupSignal.connect(lambda: print("popup"))
w.show()
sys.exit(app.exec_())
它的语法是什么?我没有找到足够的文档。你能帮忙吗?