def createEditor(self, parent, option, index): editor = QTimeEdit(parent=parent) editor.setMinimumTime(datetime.time(hour=8, minute=30, second=30)) editor.setMaximumTime(datetime.time(hour=23, minute=30, second=30)) editor.setDisplayFormat("HH:mm:ss") # setFrame(): tell whether the line edit draws itself with a frame. # If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame. editor.setFrame(False) return editor
def createEditor(self, parent, option, index): editor = QTimeEdit(parent=parent) editor.setMinimumTime(datetime.time(hour=8, minute=30, second=30)) editor.setMaximumTime(datetime.time(hour=23, minute=30, second=30)) editor.setDisplayFormat("HH:mm:ss") # setFrame(): tell whether the line edit draws itself with a frame. # If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame. editor.setFrame(False) return editor
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor = QTimeEdit(parent) editor.setDisplayFormat(TIME_FORMAT) editor.setCurrentSection(QTimeEdit.SecondSection) editor.setFrame(False) editor.setAlignment(Qt.AlignCenter) editor.setButtonSymbols(QAbstractSpinBox.NoButtons) editor.setCorrectionMode(QAbstractSpinBox.CorrectToNearestValue) editor.setKeyboardTracking(True) editor.setProperty("showGroupSeparator", False) editor.setCalendarPopup(False) return editor
class VCTimeCounter(QWidget): timeChanged = pyqtSignal(QTime) def __init__(self, parent=None): super(VCTimeCounter, self).__init__(parent) self.parent = parent self.timeedit = QTimeEdit(QTime(0, 0)) self.timeedit.setObjectName('timeCounter') self.timeedit.setStyle(QStyleFactory.create('Fusion')) self.timeedit.setFrame(False) self.timeedit.setDisplayFormat('hh:mm:ss.zzz') self.timeedit.timeChanged.connect(self.timeChangeHandler) separator = QLabel('/') separator.setObjectName('timeSeparator') self.duration = QLabel('00:00:00.000') self.duration.setObjectName('timeDuration') layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(5) layout.addWidget(self.timeedit) layout.addWidget(separator) layout.addWidget(self.duration) self.setLayout(layout) def setRange(self, minval: str, maxval: str) -> None: self.timeedit.setTimeRange(QTime.fromString(minval, 'hh:mm:ss.zzz'), QTime.fromString(maxval, 'hh:mm:ss.zzz')) def setMinimum(self, val: str = None) -> None: if val is None: self.timeedit.setMinimumTime(QTime(0, 0)) else: self.timeedit.setMinimumTime(QTime.fromString(val, 'hh:mm:ss.zzz')) def setMaximum(self, val: str) -> None: self.timeedit.setMaximumTime(QTime.fromString(val, 'hh:mm:ss.zzz')) def setTime(self, time: str) -> None: self.timeedit.setTime(QTime.fromString(time, 'hh:mm:ss.zzz')) def setDuration(self, time: str) -> None: self.duration.setText(time) self.setMaximum(time) def clearFocus(self) -> None: self.timeedit.clearFocus() def hasFocus(self) -> bool: if self.timeedit.hasFocus(): return True return super(VCTimeCounter, self).hasFocus() def reset(self) -> None: self.timeedit.setTime(QTime(0, 0)) self.setDuration('00:00:00.000') def setReadOnly(self, readonly: bool) -> None: self.timeedit.setReadOnly(readonly) if readonly: self.timeedit.setButtonSymbols(QAbstractSpinBox.NoButtons) else: self.timeedit.setButtonSymbols(QAbstractSpinBox.UpDownArrows) @pyqtSlot(QTime) def timeChangeHandler(self, newtime: QTime) -> None: if self.timeedit.hasFocus(): self.timeChanged.emit(newtime)