当前位置: 首页>>代码示例>>Python>>正文


Python QDateTimeEdit.setDateTime方法代码示例

本文整理汇总了Python中PyQt5.Qt.QDateTimeEdit.setDateTime方法的典型用法代码示例。如果您正苦于以下问题:Python QDateTimeEdit.setDateTime方法的具体用法?Python QDateTimeEdit.setDateTime怎么用?Python QDateTimeEdit.setDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.Qt.QDateTimeEdit的用法示例。


在下文中一共展示了QDateTimeEdit.setDateTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DownQDialog

# 需要导入模块: from PyQt5.Qt import QDateTimeEdit [as 别名]
# 或者: from PyQt5.Qt.QDateTimeEdit import setDateTime [as 别名]

#.........这里部分代码省略.........
            )
        )
        fixed_info.setWordWrap(True)
        downtime_layout.addWidget(fixed_info, 3, 0, 1, 3)

        duration_label = QLabel(_('Duration'))
        duration_label.setObjectName('subtitle')
        downtime_layout.addWidget(duration_label, 4, 0, 1, 1)

        duration_clock = QLabel()
        duration_clock.setPixmap(QPixmap(settings.get_image('time')))
        downtime_layout.addWidget(duration_clock, 4, 1, 1, 1)
        duration_clock.setFixedSize(16, 16)
        duration_clock.setScaledContents(True)

        self.duration.setTime(QTime(4, 00))
        self.duration.setDisplayFormat("HH'h'mm")
        downtime_layout.addWidget(self.duration, 4, 2, 1, 1)

        duration_info = QLabel(
            _('Sets the duration if it is a non-fixed downtime.')
        )
        downtime_layout.addWidget(duration_info, 5, 0, 1, 3)

        date_range_label = QLabel(_('Downtime date range'))
        date_range_label.setObjectName('subtitle')
        downtime_layout.addWidget(date_range_label, 6, 0, 1, 1)

        calendar_label = QLabel()
        calendar_label.setPixmap(QPixmap(settings.get_image('calendar')))
        calendar_label.setFixedSize(16, 16)
        calendar_label.setScaledContents(True)
        downtime_layout.addWidget(calendar_label, 6, 1, 1, 1)

        start_time_label = QLabel(_('Start time:'))
        downtime_layout.addWidget(start_time_label, 7, 0, 1, 1)

        self.start_time.setCalendarPopup(True)
        self.start_time.setDateTime(datetime.datetime.now())
        self.start_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.start_time, 7, 1, 1, 2)

        end_time_label = QLabel(_('End time:'))
        downtime_layout.addWidget(end_time_label, 8, 0, 1, 1)

        self.end_time.setCalendarPopup(True)
        self.end_time.setDateTime(datetime.datetime.now() + datetime.timedelta(hours=2))
        self.end_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.end_time, 8, 1, 1, 2)

        self.comment_edit.setText(comment)
        self.comment_edit.setMaximumHeight(60)
        downtime_layout.addWidget(self.comment_edit, 9, 0, 1, 3)

        request_btn = QPushButton(_('REQUEST DOWNTIME'), self)
        request_btn.clicked.connect(self.handle_accept)
        request_btn.setObjectName('valid')
        request_btn.setMinimumHeight(30)
        request_btn.setDefault(True)
        downtime_layout.addWidget(request_btn, 10, 0, 1, 3)

        main_layout.addWidget(downtime_widget)

    def duration_to_seconds(self):
        """
        Return "duration" QTimeEdit value in seconds

        :return: "duration" in seconds
        :rtype: int
        """

        return QTime(0, 0).secsTo(self.duration.time())

    def handle_accept(self):
        """
        Check if end_time timestamp is not lower than start_time

        """

        if self.start_time.dateTime().toTime_t() > self.end_time.dateTime().toTime_t():
            logger.warning('Try to add Downtime with "End Time" lower than "Start Time"')
        else:
            self.accept()

    def mousePressEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        self.offset = event.pos()

    def mouseMoveEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        try:
            x = event.globalX()
            y = event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x - x_w, y - y_w)
        except AttributeError as e:
            logger.warning('Move Event %s: %s', self.objectName(), str(e))
开发者ID:Alignak-monitoring-contrib,项目名称:alignak-app,代码行数:104,代码来源:actions.py

示例2: HistoryWidget

# 需要导入模块: from PyQt5.Qt import QDateTimeEdit [as 别名]
# 或者: from PyQt5.Qt.QDateTimeEdit import setDateTime [as 别名]

#.........这里部分代码省略.........
        buttonUpdate.clicked.connect(self.buttonUpdateClicked)

        # finalLy initialize
        self.checkBoxLBPMajor.setChecked(self._v_curve_checked[0])
        self.checkBoxLBPMinor.setChecked(self._v_curve_checked[1])
        self.checkBoxRBPMajor.setChecked(self._v_curve_checked[2])
        self.checkBoxRBPMinor.setChecked(self._v_curve_checked[3])
        self.checkBoxLRPTheory.setChecked(self._v_curve_checked[4])
        self.checkBoxLRPReal.setChecked(self._v_curve_checked[5])
        self.checkBoxRRPTheory.setChecked(self._v_curve_checked[6])
        self.checkBoxRRPReal.setChecked(self._v_curve_checked[7])

    def buttonOpenClicked(self):
        fileDialog = QFileDialog(
            self, "打开历史数据文件", QApplication.applicationDirPath() + "/../data", "Database File (*.db *.mdb)"
        )
        if fileDialog.exec_() == QDialog.Rejected:
            return
        # clear curve
        self.curveHistory.clear()
        #
        filePaths = fileDialog.selectedFiles()
        if filePaths.isEmpty():
            return
        filePath = filePaths.first()
        if filePath.isEmpty():
            return
        # open database
        if not DatabaseMgr().open(filePath):
            return
        #
        startTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().startTime())
        endTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().endTime())
        self.dateTimeEditStart.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTime(endTime)
        self.dateTimeEditStart.setDateTime(startTime)

        # title of curve
        self.curveHistory.setTitle("历史数据回放" + "(" + QFileInfo(filePath).fileName() + ")")

    def buttonExportClicked(self):
        (filePaths, filter) = QFileDialog.getOpenFileNames(
            parent=self,
            caption="转换数据库文件为文本格式",
            directory=QApplication.applicationDirPath() + "/../data",
            filter="Database file (*.db * mdb)",
        )
        if not filePaths:
            return
        #
        if DatabaseMgr().convertToText(filePaths):
            QMessageBox.information(self, "格式转换", "转换成功!")
        else:
            QMessageBox.warning(self, "格式转换", "转换失败!")

    def dateTimeStartChanged(self, dateTime):
        dateTimeEnd = self.dateTimeEditEnd.dateTime()
        if dateTime > dateTimeEnd:
            self.dateTimeEditStart.setDateTime(dateTimeEnd)

    def dateTimeEndChanged(self, dateTime):
        dateTimeStart = self.dateTimeEditStart.dateTime()
        if dateTime < dateTimeStart:
            self.dateTimeEditEnd.setDateTime(dateTimeStart)
开发者ID:iclosure,项目名称:carmonitor,代码行数:69,代码来源:history_widget.py


注:本文中的PyQt5.Qt.QDateTimeEdit.setDateTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。