我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用PyQt5.QtWidgets.QDateTimeEdit()。
def createEditor(self, parent, styleOption, index): if index.column() == 1: editor = QDateTimeEdit(parent) editor.setDisplayFormat(self.parent().currentDateFormat) editor.setCalendarPopup(True) return editor editor = QLineEdit(parent) # create a completer with the strings in the column as model allStrings = [] for i in range(1, index.model().rowCount()): strItem = index.model().data(index.sibling(i, index.column()), Qt.EditRole) if strItem not in allStrings: allStrings.append(strItem) autoComplete = QCompleter(allStrings) editor.setCompleter(autoComplete) editor.editingFinished.connect(self.commitAndCloseEditor) return editor
def test_initialize_downtime(self): """Initialize Downtime""" under_test = DownQDialog() under_test.initialize('host', 'my_host', 'Downtime requested by App') self.assertTrue(under_test.fixed) self.assertTrue(under_test.duration) self.assertIsInstance(under_test.duration, QTimeEdit) self.assertEqual(under_test.duration_to_seconds(), 14400) self.assertTrue(under_test.start_time) self.assertIsInstance(under_test.start_time, QDateTimeEdit) self.assertTrue(under_test.end_time) self.assertIsInstance(under_test.end_time, QDateTimeEdit) self.assertEqual( under_test.end_time.dateTime().toTime_t() - under_test.start_time.dateTime().toTime_t(), 7200 ) self.assertEqual('Downtime requested by App', under_test.comment_edit.toPlainText())
def __init__(self, i_unix_time_it, i_parent = None): super(DateTimeDialog, self).__init__(i_parent) vbox = QtWidgets.QVBoxLayout(self) self.date_time_edit = QtWidgets.QDateTimeEdit(self) self.date_time_edit.setCalendarPopup(True) present_qdatetime = QtCore.QDateTime() present_qdatetime.setMSecsSinceEpoch(1000 * i_unix_time_it) self.date_time_edit.setDateTime(present_qdatetime) vbox.addWidget(self.date_time_edit) self.button_box = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self ) vbox.addWidget(self.button_box) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) # -accept and reject are "slots" built into Qt
def setEditorData(self, editor, index): if isinstance(editor, QLineEdit): editor.setText(index.model().data(index, Qt.EditRole)) elif isinstance(editor, QDateTimeEdit): editor.setDate(QDate.fromString( index.model().data(index, Qt.EditRole), self.parent().currentDateFormat))
def setModelData(self, editor, model, index): if isinstance(editor, QLineEdit): model.setData(index, editor.text()) elif isinstance(editor, QDateTimeEdit): model.setData(index, editor.date().toString(self.parent().currentDateFormat))