我想创建一个日历,当我按下该日历中的日期时,它将被复制到某些字段中。当前,我正在尝试仅填充一个字段,并且收到错误“ QDateEdit对象没有属性“ setText” 代码:
class Ui_DE(object):
def setupUi(self, DE):
DE.setObjectName("DE")
DE.resize(1149, 517)
font = QtGui.QFont()
font.setPointSize(10)
DE.setFont(font)
self.centralwidget = QtWidgets.QWidget(DE)
self.centralwidget.setObjectName("centralwidget")
self.calButton = QtWidgets.QPushButton(DE)
self.calButton.setIcon(QtGui.QIcon('calendar.png'))
self.calButton.setStyleSheet('border: 0px; padding: 0px;')
self.calButton.setCursor(QtCore.Qt.ArrowCursor)
self.calButton.clicked.connect(self.showCalWid)
self.calButton.setGeometry(QtCore.QRect(650, 50, 256, 183))
self.btnStart = QtWidgets.QPushButton(DE)
self.btnStart.setGeometry(QtCore.QRect(140, 60, 91, 21))
self.btnStart.setObjectName("Start")
self.GermanyBrowse = QtWidgets.QPushButton(DE)
self.GermanyBrowse.setGeometry(QtCore.QRect(240, 60, 91, 21))
self.GermanyBrowse.setObjectName("GermanyBrowse")
self.GermanyBrowse.clicked.connect(self.getfile_germany)
self.GermanyLabel = QtWidgets.QLabel(DE)
self.GermanyLabel.setGeometry(QtCore.QRect(150, 60, 71, 21))
self.GermanyLabel.setObjectName("GermanyLabel")
self.GermanyDate = QtWidgets.QDateEdit(DE)
self.GermanyDate.setGeometry(QtCore.QRect(370, 60, 110, 22))
self.GermanyDate.setObjectName("GermanyDate")
self.retranslateUi(DE)
def showCalWid(self):
self.calendar = QtWidgets.QCalendarWidget()
self.calendar.setMinimumDate(QtCore.QDate(1900, 1, 1))
self.calendar.setMaximumDate(QtCore.QDate(3000, 1, 1))
self.calendar.setGridVisible(True)
self.calendar.clicked.connect(self.updateDate)
self.calendar.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.calendar.setStyleSheet('background: white; color: black')
self.calendar.setGridVisible(True)
pos = QtGui.QCursor.pos()
self.calendar.setGeometry(pos.x(), pos.y(), 300, 200)
self.calendar.show()
def updateDate(self,*args):
getDate = self.calendar.selectedDate().toString()
self.GermanyDate.setText(getDate)
self.calendar.deleteLater()
def retranslateUi(self, DE):
_translate = QtCore.QCoreApplication.translate
DE.setWindowTitle(_translate("DE", "Dialog"))
self.GermanyBrowse.setText(_translate("DE", "Browse"))
我正在尝试将日历中选择的日期复制到self.GermanyDate
任何想法我该怎么做?
答案 0 :(得分:1)
您必须传递QDate而不是字符串:
self.GermanyDate.setDate(self.calendar.selectedDate())