class CalendarDialog(QDialog): picked_date = None source = None parent = None def __init__(self, parent, windowTitle='Date picker'): super().__init__(parent, windowTitle=windowTitle) self.parent = parent self.setLayout(QVBoxLayout()) self.mainArea = gui.widgetBox(self) self.layout().addWidget(self.mainArea) self.cal = QCalendarWidget(self) self.cal.setGridVisible(True) self.cal.move(20, 20) self.cal.clicked[QDate].connect(self.set_date) self.mainArea.layout().addWidget(self.cal) # Set the default date. self.picked_date = self.cal.selectedDate().toString('yyyy/MM/dd') gui.button(self.mainArea, self, 'OK', lambda: QDialog.accept(self)) def set_date(self, date): self.picked_date = date.toString('yyyy/MM/dd')
class DateField(Field): def render(self): """Return a QWidget object that can be added to a Form object using addField.""" self.widget = QCalendarWidget() return self.widget def get_value(self): return self.widget.selectedDate().toString(Qt.ISODate)
def render(self): """Return a QWidget object that can be added to a Form object using addField.""" self.widget = QCalendarWidget() return self.widget