def set_format(self, column): str_format = Qt.ISODate if self.have_date and self.have_time: self.setDisplayFormat("yyyy-MM-dd hh:mm:ss") c_format = "%Y-%m-%d %H:%M:%S" min_datetime, max_datetime = self.find_range(column, c_format) self.min_datetime = QDateTime.fromString(min_datetime, str_format) self.max_datetime = QDateTime.fromString(max_datetime, str_format) self.setCalendarPopup(True) self.calendarWidget = gui.CalendarWidgetWithTime( self, time=self.min_datetime.time()) self.calendarWidget.timeedit.timeChanged.connect(self.set_datetime) self.setCalendarWidget(self.calendarWidget) self.setDateTimeRange(self.min_datetime, self.max_datetime) elif self.have_date and not self.have_time: self.setDisplayFormat("yyyy-MM-dd") self.setCalendarPopup(True) min_datetime, max_datetime = self.find_range(column, "%Y-%m-%d") self.min_datetime = QDate.fromString(min_datetime, str_format) self.max_datetime = QDate.fromString(max_datetime, str_format) self.setDateRange(self.min_datetime, self.max_datetime) elif not self.have_date and self.have_time: self.setDisplayFormat("hh:mm:ss") min_datetime, max_datetime = self.find_range(column, "%H:%M:%S") self.min_datetime = QTime.fromString(min_datetime, str_format) self.max_datetime = QTime.fromString(max_datetime, str_format) self.setTimeRange(self.min_datetime, self.max_datetime)
def __map_to_datetime(self, value: float) -> QDateTime: return QDateTime.fromString(self._variable.repr_val(value), self._format)