这是您可以用来提示输入日期的简单类:
class DateDialog(QDialog): def __init__(self, parent = None): super(DateDialog, self).__init__(parent) layout = QVBoxLayout(self) # nice widget for editing the date self.datetime = QDateTimeEdit(self) self.datetime.setCalendarPopup(True) self.datetime.setDateTime(QDateTime.currentDateTime()) layout.addWidget(self.datetime) # OK and Cancel buttons buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) layout.addWidget(buttons) # get current date and time from the dialog def dateTime(self): return self.datetime.dateTime() # static method to create the dialog and return (date, time, accepted) @staticmethod def getDateTime(parent = None): dialog = DateDialog(parent) result = dialog.exec_() date = dialog.dateTime() return (date.date(), date.time(), result == QDialog.Accepted)
并使用它:
date, time, ok = DateDialog.getDateTime()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)