其他分享
首页 > 其他分享> > QT乱翻书-DateTime

QT乱翻书-DateTime

作者:互联网

跳转到大纲  码云

 

QT乱翻书-DateTime

 

 

#ifndef DIALOG_H
#define DIALOG_H

#include    <QDialog>
#include    <QTimer>
#include    <QTime>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT
private:
    QTimer *fTimer;  //定时器

    QTime   fTimeCounter;//计时器

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:
    void on_timer_timeout(); //定时器中断处理槽函数,手工定义


    void on_btnGetTime_clicked();//读取当前时间

    void on_calendarWidget_selectionChanged(); //Calender 选择日期

    void on_btnSetTime_clicked();  // 读取当前日期时间  按键

    void on_btnSetDate_clicked(); //设置日期  按键

    void on_btnSetDateTime_clicked();   //设置日期时间案件

    void on_btnSetIntv_clicked();   //设置周期  按键

    void on_btnStart_clicked();  //开始 定时器 按键

    void on_btnStop_clicked();      //停止定时器按键

private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H
/********************************************************************************
** Form generated from reading UI file 'dialog.ui'
**
** Created by: Qt User Interface Compiler version 5.9.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_DIALOG_H
#define UI_DIALOG_H

#include <QtCore/QDate>
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCalendarWidget>
#include <QtWidgets/QDateEdit>
#include <QtWidgets/QDateTimeEdit>
#include <QtWidgets/QDialog>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLCDNumber>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QTimeEdit>
#include <QtWidgets/QVBoxLayout>

QT_BEGIN_NAMESPACE

class Ui_Dialog
{
public:
    QHBoxLayout *horizontalLayout_2;
    QVBoxLayout *verticalLayout_3;
    QGroupBox *groupBox_2;
    QGridLayout *gridLayout;
    QLabel *label_2;
    QTimeEdit *timeEdit;
    QLabel *label_3;
    QPushButton *btnSetDate;
    QPushButton *btnSetDateTime;
    QLabel *label;
    QDateEdit *dateEdit;
    QPushButton *btnSetTime;
    QLineEdit *editTime;
    QLineEdit *editDate;
    QPushButton *btnGetTime;
    QSpacerItem *horizontalSpacer_2;
    QLineEdit *editDateTime;
    QDateTimeEdit *dateTimeEdit;
    QLabel *LabDateTime;
    QGroupBox *groupBox;
    QVBoxLayout *verticalLayout;
    QGridLayout *gridLayout_2;
    QPushButton *btnStart;
    QPushButton *btnStop;
    QLabel *label_4;
    QSpinBox *spinBoxIntv;
    QPushButton *btnSetIntv;
    QSpacerItem *horizontalSpacer;
    QLabel *LabElapsTime;
    QHBoxLayout *horizontalLayout;
    QLCDNumber *LCDHour;
    QLCDNumber *LCDMin;
    QLCDNumber *LCDSec;
    QProgressBar *progressBar;
    QVBoxLayout *verticalLayout_2;
    QGroupBox *groupBox_3;
    QGridLayout *gridLayout_3;
    QLineEdit *editCalendar;
    QCalendarWidget *calendarWidget;
    QLabel *label_5;
    QSpacerItem *verticalSpacer;
    QPushButton *btnClose;
    QSpacerItem *verticalSpacer_2;

    void setupUi(QDialog *Dialog)
    {
        if (Dialog->objectName().isEmpty())
            Dialog->setObjectName(QStringLiteral("Dialog"));
        Dialog->resize(788, 374);
        QFont font;
        font.setPointSize(10);
        Dialog->setFont(font);
        horizontalLayout_2 = new QHBoxLayout(Dialog);
        horizontalLayout_2->setSpacing(6);
        horizontalLayout_2->setContentsMargins(11, 11, 11, 11);
        horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
        verticalLayout_3 = new QVBoxLayout();
        verticalLayout_3->setSpacing(6);
        verticalLayout_3->setObjectName(QStringLiteral("verticalLayout_3"));
        groupBox_2 = new QGroupBox(Dialog);
        groupBox_2->setObjectName(QStringLiteral("groupBox_2"));
        gridLayout = new QGridLayout(groupBox_2);
        gridLayout->setSpacing(6);
        gridLayout->setContentsMargins(11, 11, 11, 11);
        gridLayout->setObjectName(QStringLiteral("gridLayout"));
        label_2 = new QLabel(groupBox_2);
        label_2->setObjectName(QStringLiteral("label_2"));

        gridLayout->addWidget(label_2, 2, 0, 1, 1);

        timeEdit = new QTimeEdit(groupBox_2);
        timeEdit->setObjectName(QStringLiteral("timeEdit"));
        timeEdit->setCalendarPopup(true);
        timeEdit->setTime(QTime(15, 30, 55));

        gridLayout->addWidget(timeEdit, 1, 1, 1, 1);

        label_3 = new QLabel(groupBox_2);
        label_3->setObjectName(QStringLiteral("label_3"));

        gridLayout->addWidget(label_3, 3, 0, 1, 1);

        btnSetDate = new QPushButton(groupBox_2);
        btnSetDate->setObjectName(QStringLiteral("btnSetDate"));

        gridLayout->addWidget(btnSetDate, 2, 4, 1, 1);

        btnSetDateTime = new QPushButton(groupBox_2);
        btnSetDateTime->setObjectName(QStringLiteral("btnSetDateTime"));

        gridLayout->addWidget(btnSetDateTime, 3, 4, 1, 1);

        label = new QLabel(groupBox_2);
        label->setObjectName(QStringLiteral("label"));

        gridLayout->addWidget(label, 1, 0, 1, 1);

        dateEdit = new QDateEdit(groupBox_2);
        dateEdit->setObjectName(QStringLiteral("dateEdit"));
        dateEdit->setCurrentSection(QDateTimeEdit::YearSection);
        dateEdit->setCalendarPopup(true);
        dateEdit->setCurrentSectionIndex(0);
        dateEdit->setDate(QDate(2016, 11, 21));

        gridLayout->addWidget(dateEdit, 2, 1, 1, 1);

        btnSetTime = new QPushButton(groupBox_2);
        btnSetTime->setObjectName(QStringLiteral("btnSetTime"));

        gridLayout->addWidget(btnSetTime, 1, 4, 1, 1);

        editTime = new QLineEdit(groupBox_2);
        editTime->setObjectName(QStringLiteral("editTime"));

        gridLayout->addWidget(editTime, 1, 3, 1, 1);

        editDate = new QLineEdit(groupBox_2);
        editDate->setObjectName(QStringLiteral("editDate"));

        gridLayout->addWidget(editDate, 2, 3, 1, 1);

        btnGetTime = new QPushButton(groupBox_2);
        btnGetTime->setObjectName(QStringLiteral("btnGetTime"));

        gridLayout->addWidget(btnGetTime, 0, 0, 1, 2);

        horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        gridLayout->addItem(horizontalSpacer_2, 2, 2, 1, 1);

        editDateTime = new QLineEdit(groupBox_2);
        editDateTime->setObjectName(QStringLiteral("editDateTime"));
        editDateTime->setMinimumSize(QSize(150, 0));

        gridLayout->addWidget(editDateTime, 3, 3, 1, 1);

        dateTimeEdit = new QDateTimeEdit(groupBox_2);
        dateTimeEdit->setObjectName(QStringLiteral("dateTimeEdit"));
        dateTimeEdit->setMinimumSize(QSize(160, 0));
        dateTimeEdit->setDateTime(QDateTime(QDate(2018, 10, 9), QTime(8, 21, 28)));
        dateTimeEdit->setDate(QDate(2018, 10, 9));
        dateTimeEdit->setTime(QTime(8, 21, 28));
        dateTimeEdit->setMaximumDateTime(QDateTime(QDate(3000, 12, 31), QTime(23, 59, 59)));
        dateTimeEdit->setMinimumDateTime(QDateTime(QDate(1763, 9, 14), QTime(0, 0, 0)));
        dateTimeEdit->setMinimumDate(QDate(1763, 9, 14));
        dateTimeEdit->setCurrentSection(QDateTimeEdit::YearSection);
        dateTimeEdit->setCalendarPopup(false);
        dateTimeEdit->setCurrentSectionIndex(0);
        dateTimeEdit->setTimeSpec(Qt::LocalTime);

        gridLayout->addWidget(dateTimeEdit, 3, 1, 1, 1);

        LabDateTime = new QLabel(groupBox_2);
        LabDateTime->setObjectName(QStringLiteral("LabDateTime"));
        LabDateTime->setAlignment(Qt::AlignCenter);

        gridLayout->addWidget(LabDateTime, 0, 3, 1, 1);


        verticalLayout_3->addWidget(groupBox_2);

        groupBox = new QGroupBox(Dialog);
        groupBox->setObjectName(QStringLiteral("groupBox"));
        verticalLayout = new QVBoxLayout(groupBox);
        verticalLayout->setSpacing(6);
        verticalLayout->setContentsMargins(11, 11, 11, 11);
        verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
        gridLayout_2 = new QGridLayout();
        gridLayout_2->setSpacing(6);
        gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
        btnStart = new QPushButton(groupBox);
        btnStart->setObjectName(QStringLiteral("btnStart"));

        gridLayout_2->addWidget(btnStart, 0, 0, 1, 2);

        btnStop = new QPushButton(groupBox);
        btnStop->setObjectName(QStringLiteral("btnStop"));
        btnStop->setEnabled(false);

        gridLayout_2->addWidget(btnStop, 0, 2, 1, 2);

        label_4 = new QLabel(groupBox);
        label_4->setObjectName(QStringLiteral("label_4"));

        gridLayout_2->addWidget(label_4, 1, 0, 1, 1);

        spinBoxIntv = new QSpinBox(groupBox);
        spinBoxIntv->setObjectName(QStringLiteral("spinBoxIntv"));
        spinBoxIntv->setMaximum(999999);
        spinBoxIntv->setValue(1000);

        gridLayout_2->addWidget(spinBoxIntv, 1, 1, 1, 2);

        btnSetIntv = new QPushButton(groupBox);
        btnSetIntv->setObjectName(QStringLiteral("btnSetIntv"));

        gridLayout_2->addWidget(btnSetIntv, 1, 3, 1, 2);

        horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        gridLayout_2->addItem(horizontalSpacer, 1, 5, 1, 1);

        LabElapsTime = new QLabel(groupBox);
        LabElapsTime->setObjectName(QStringLiteral("LabElapsTime"));

        gridLayout_2->addWidget(LabElapsTime, 0, 5, 1, 1);


        verticalLayout->addLayout(gridLayout_2);

        horizontalLayout = new QHBoxLayout();
        horizontalLayout->setSpacing(6);
        horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
        LCDHour = new QLCDNumber(groupBox);
        LCDHour->setObjectName(QStringLiteral("LCDHour"));
        LCDHour->setSmallDecimalPoint(false);
        LCDHour->setDigitCount(2);
        LCDHour->setProperty("value", QVariant(10));
        LCDHour->setProperty("intValue", QVariant(10));

        horizontalLayout->addWidget(LCDHour);

        LCDMin = new QLCDNumber(groupBox);
        LCDMin->setObjectName(QStringLiteral("LCDMin"));
        LCDMin->setDigitCount(2);
        LCDMin->setProperty("intValue", QVariant(26));

        horizontalLayout->addWidget(LCDMin);

        LCDSec = new QLCDNumber(groupBox);
        LCDSec->setObjectName(QStringLiteral("LCDSec"));
        LCDSec->setDigitCount(2);
        LCDSec->setProperty("intValue", QVariant(35));

        horizontalLayout->addWidget(LCDSec);


        verticalLayout->addLayout(horizontalLayout);

        progressBar = new QProgressBar(groupBox);
        progressBar->setObjectName(QStringLiteral("progressBar"));
        progressBar->setValue(10);
        progressBar->setTextVisible(true);

        verticalLayout->addWidget(progressBar);


        verticalLayout_3->addWidget(groupBox);


        horizontalLayout_2->addLayout(verticalLayout_3);

        verticalLayout_2 = new QVBoxLayout();
        verticalLayout_2->setSpacing(6);
        verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2"));
        groupBox_3 = new QGroupBox(Dialog);
        groupBox_3->setObjectName(QStringLiteral("groupBox_3"));
        gridLayout_3 = new QGridLayout(groupBox_3);
        gridLayout_3->setSpacing(6);
        gridLayout_3->setContentsMargins(11, 11, 11, 11);
        gridLayout_3->setObjectName(QStringLiteral("gridLayout_3"));
        editCalendar = new QLineEdit(groupBox_3);
        editCalendar->setObjectName(QStringLiteral("editCalendar"));

        gridLayout_3->addWidget(editCalendar, 0, 1, 1, 1);

        calendarWidget = new QCalendarWidget(groupBox_3);
        calendarWidget->setObjectName(QStringLiteral("calendarWidget"));
        calendarWidget->setGridVisible(false);

        gridLayout_3->addWidget(calendarWidget, 1, 0, 1, 2);

        label_5 = new QLabel(groupBox_3);
        label_5->setObjectName(QStringLiteral("label_5"));

        gridLayout_3->addWidget(label_5, 0, 0, 1, 1);


        verticalLayout_2->addWidget(groupBox_3);

        verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);

        verticalLayout_2->addItem(verticalSpacer);

        btnClose = new QPushButton(Dialog);
        btnClose->setObjectName(QStringLiteral("btnClose"));

        verticalLayout_2->addWidget(btnClose);

        verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);

        verticalLayout_2->addItem(verticalSpacer_2);


        horizontalLayout_2->addLayout(verticalLayout_2);


        retranslateUi(Dialog);
        QObject::connect(btnClose, SIGNAL(clicked()), Dialog, SLOT(close()));

        QMetaObject::connectSlotsByName(Dialog);
    } // setupUi

    void retranslateUi(QDialog *Dialog)
    {
        Dialog->setWindowTitle(QApplication::translate("Dialog", "\346\227\245\346\234\237\346\227\266\351\227\264\357\274\214\345\256\232\346\227\266\345\231\250", Q_NULLPTR));
        groupBox_2->setTitle(QApplication::translate("Dialog", "\346\227\245\346\234\237\346\227\266\351\227\264", Q_NULLPTR));
        label_2->setText(QApplication::translate("Dialog", "\346\227\245  \346\234\237", Q_NULLPTR));
        timeEdit->setDisplayFormat(QApplication::translate("Dialog", "HH:mm:ss", Q_NULLPTR));
        label_3->setText(QApplication::translate("Dialog", "\346\227\245\346\234\237\346\227\266\351\227\264", Q_NULLPTR));
        btnSetDate->setText(QApplication::translate("Dialog", "\350\256\276\347\275\256\346\227\245\346\234\237", Q_NULLPTR));
        btnSetDateTime->setText(QApplication::translate("Dialog", "\350\256\276\347\275\256\346\227\245\346\234\237\346\227\266\351\227\264", Q_NULLPTR));
        label->setText(QApplication::translate("Dialog", "\346\227\266  \351\227\264", Q_NULLPTR));
        dateEdit->setDisplayFormat(QApplication::translate("Dialog", "yyyy\345\271\264M\346\234\210d\346\227\245", Q_NULLPTR));
        btnSetTime->setText(QApplication::translate("Dialog", "\350\256\276\347\275\256\346\227\266\351\227\264", Q_NULLPTR));
        btnGetTime->setText(QApplication::translate("Dialog", "\350\257\273\345\217\226\345\275\223\345\211\215\346\227\245\346\234\237\346\227\266\351\227\264", Q_NULLPTR));
        dateTimeEdit->setDisplayFormat(QApplication::translate("Dialog", "yyyy-MM-dd HH:mm:ss", Q_NULLPTR));
        LabDateTime->setText(QApplication::translate("Dialog", "\345\255\227\347\254\246\344\270\262\346\230\276\347\244\272", Q_NULLPTR));
        groupBox->setTitle(QApplication::translate("Dialog", "\345\256\232\346\227\266\345\231\250", Q_NULLPTR));
        btnStart->setText(QApplication::translate("Dialog", "\345\274\200\345\247\213", Q_NULLPTR));
        btnStop->setText(QApplication::translate("Dialog", "\345\201\234\346\255\242", Q_NULLPTR));
        label_4->setText(QApplication::translate("Dialog", "\345\256\232\346\227\266\345\221\250\346\234\237", Q_NULLPTR));
        spinBoxIntv->setSuffix(QApplication::translate("Dialog", " ms", Q_NULLPTR));
        btnSetIntv->setText(QApplication::translate("Dialog", "\350\256\276\347\275\256\345\221\250\346\234\237", Q_NULLPTR));
        LabElapsTime->setText(QApplication::translate("Dialog", "\346\265\201\351\200\235\346\227\266\351\227\264", Q_NULLPTR));
        groupBox_3->setTitle(QApplication::translate("Dialog", "\346\227\245\345\216\206\351\200\211\346\213\251", Q_NULLPTR));
        label_5->setText(QApplication::translate("Dialog", "\351\200\211\346\213\251\347\232\204\346\227\245\346\234\237\357\274\232", Q_NULLPTR));
        btnClose->setText(QApplication::translate("Dialog", "\351\200\200  \345\207\272", Q_NULLPTR));
    } // retranslateUi

};

namespace Ui {
    class Dialog: public Ui_Dialog {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_DIALOG_H
#include "dialog.h"
#include "ui_dialog.h"

#include    <QDateTime>
#include    <QString>

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    fTimer=new QTimer(this);  //创建定时器
    fTimer->stop();
    fTimer->setInterval(1000);//设置定时周期,单位:毫秒
    connect(fTimer,SIGNAL(timeout()),this,SLOT(on_timer_timeout())); //关联定时器的信号与槽
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_timer_timeout()
{ //定时器中断响应槽函数
    QTime curTime=QTime::currentTime(); //获取当前时间

    ui->LCDHour->display(curTime.hour()); //显示  小时

    ui->LCDMin->display(curTime.minute());//显示  分钟

    ui->LCDSec->display(curTime.second());//显示  秒

    int va=ui->progressBar->value(); //读取progressBar的数值
    va++;
    if (va>100)
        va=0;
    ui->progressBar->setValue(va); //设置progressBar的数值
}

void Dialog::on_btnGetTime_clicked()
{ //获取当前日期时间,为三个专用编辑器设置日期时间数据,并转换为字符串在LineEdit里显示
    QDateTime curDateTime=QDateTime::currentDateTime(); //读取当前日期时间

    ui->timeEdit->setTime(curDateTime.time()); //设置时间
    ui->editTime->setText(curDateTime.toString("hh:mm:ss"));//转换为字符串显示

    ui->dateEdit->setDate(curDateTime.date());//设置日期
    ui->editDate->setText(curDateTime.toString("yyyy-MM-dd"));//转换为字符串显示

    ui->dateTimeEdit->setDateTime(curDateTime);//设置日期时间
    ui->editDateTime->setText(curDateTime.toString("yyyy-MM-dd hh:mm:ss"));//转换为字符串显示
}

void Dialog::on_calendarWidget_selectionChanged()
{ //在日历上选择日期
    QDate dt=ui->calendarWidget->selectedDate(); //读取选择的日期时间
    QString str=dt.toString("yyyy年M月d日");//转换为字符串
    ui->editCalendar->setText(str); //字符串显示日期
}

void Dialog::on_btnSetTime_clicked()
{ //字符串转换为QTime
    QString str=ui->editTime->text(); //读取字符串表示的时间
    //    str=str.trimmed();//去掉空格
    if (!str.isEmpty())
    {
        QTime tm=QTime::fromString(str,"hh:mm:ss"); //从字符串转换为QTime
        ui->timeEdit->setTime(tm); //设置时间
    }
}

void Dialog::on_btnSetDate_clicked()
{//字符串转换为 QDate
    QString str=ui->editDate->text(); //读取字符串表示的日期
//    str=str.trimmed();//去掉空格
    if (!str.isEmpty())
    {
        QDate dt=QDate::fromString(str,"yyyy-MM-dd");//从字符串转换为 QDate
        ui->dateEdit->setDate(dt);//设置日期
    }
}

void Dialog::on_btnSetDateTime_clicked()
{//字符串转换为 QDateTime
    QString str=ui->editDateTime->text();//读取字符串表示的日期
    str=str.trimmed();//去掉空格
    if (!str.isEmpty())
    {
        QDateTime datetime=QDateTime::fromString(str,"yyyy-MM-dd hh:mm:ss"); //从字符串转换为 QDateTime
        ui->dateTimeEdit->setDateTime(datetime);//设置日期时间
    }
}

void Dialog::on_btnSetIntv_clicked()
{ //设置定时器周期
    fTimer->setInterval(ui->spinBoxIntv->value()); //设置定时器的周期
}

void Dialog::on_btnStart_clicked()
{
    fTimer->start();//定时器开始工作
    fTimeCounter.start();//计时器开始工作
//更新各按键的状态
    ui->btnStart->setEnabled(false);
    ui->btnStop->setEnabled(true);
    ui->btnSetIntv->setEnabled(false);
}

void Dialog::on_btnStop_clicked()
{
    fTimer->stop(); //定时器停止

    int tmMsec=fTimeCounter.elapsed();//毫秒数
    int ms=tmMsec%1000; //余数毫秒
    int sec=tmMsec/1000; //整秒

    QString str=QString::asprintf("流逝时间:%d 秒,%d 毫秒",sec,ms);
    ui->LabElapsTime->setText(str); //显示流逝的时间

    ui->btnStart->setEnabled(true); //更新按键状态
    ui->btnStop->setEnabled(false);
    ui->btnSetIntv->setEnabled(true);
}
#include "dialog.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();

    return a.exec();
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1044</width>
    <height>476</height>
   </rect>
  </property>
  <property name="font">
   <font>
    <pointsize>10</pointsize>
   </font>
  </property>
  <property name="windowTitle">
   <string>日期时间,定时器</string>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout_2">
   <item>
    <layout class="QVBoxLayout" name="verticalLayout_3">
     <item>
      <widget class="QGroupBox" name="groupBox_2">
       <property name="title">
        <string>日期时间</string>
       </property>
       <layout class="QGridLayout" name="gridLayout">
        <item row="2" column="0">
         <widget class="QLabel" name="label_2">
          <property name="text">
           <string>日  期</string>
          </property>
         </widget>
        </item>
        <item row="1" column="1">
         <widget class="QTimeEdit" name="timeEdit">
          <property name="displayFormat">
           <string>HH:mm:ss</string>
          </property>
          <property name="calendarPopup">
           <bool>true</bool>
          </property>
          <property name="time">
           <time>
            <hour>15</hour>
            <minute>30</minute>
            <second>55</second>
           </time>
          </property>
         </widget>
        </item>
        <item row="3" column="0">
         <widget class="QLabel" name="label_3">
          <property name="text">
           <string>日期时间</string>
          </property>
         </widget>
        </item>
        <item row="2" column="4">
         <widget class="QPushButton" name="btnSetDate">
          <property name="text">
           <string>设置日期</string>
          </property>
         </widget>
        </item>
        <item row="3" column="4">
         <widget class="QPushButton" name="btnSetDateTime">
          <property name="text">
           <string>设置日期时间</string>
          </property>
         </widget>
        </item>
        <item row="1" column="0">
         <widget class="QLabel" name="label">
          <property name="text">
           <string>时  间</string>
          </property>
         </widget>
        </item>
        <item row="2" column="1">
         <widget class="QDateEdit" name="dateEdit">
          <property name="currentSection">
           <enum>QDateTimeEdit::YearSection</enum>
          </property>
          <property name="displayFormat">
           <string>yyyy年M月d日</string>
          </property>
          <property name="calendarPopup">
           <bool>true</bool>
          </property>
          <property name="currentSectionIndex">
           <number>0</number>
          </property>
          <property name="date">
           <date>
            <year>2016</year>
            <month>11</month>
            <day>21</day>
           </date>
          </property>
         </widget>
        </item>
        <item row="1" column="4">
         <widget class="QPushButton" name="btnSetTime">
          <property name="text">
           <string>设置时间</string>
          </property>
         </widget>
        </item>
        <item row="1" column="3">
         <widget class="QLineEdit" name="editTime"/>
        </item>
        <item row="2" column="3">
         <widget class="QLineEdit" name="editDate"/>
        </item>
        <item row="0" column="0" colspan="2">
         <widget class="QPushButton" name="btnGetTime">
          <property name="text">
           <string>读取当前日期时间</string>
          </property>
         </widget>
        </item>
        <item row="2" column="2">
         <spacer name="horizontalSpacer_2">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
        <item row="3" column="3">
         <widget class="QLineEdit" name="editDateTime">
          <property name="minimumSize">
           <size>
            <width>150</width>
            <height>0</height>
           </size>
          </property>
         </widget>
        </item>
        <item row="3" column="1">
         <widget class="QDateTimeEdit" name="dateTimeEdit">
          <property name="minimumSize">
           <size>
            <width>160</width>
            <height>0</height>
           </size>
          </property>
          <property name="dateTime">
           <datetime>
            <hour>8</hour>
            <minute>21</minute>
            <second>28</second>
            <year>2018</year>
            <month>10</month>
            <day>9</day>
           </datetime>
          </property>
          <property name="date">
           <date>
            <year>2018</year>
            <month>10</month>
            <day>9</day>
           </date>
          </property>
          <property name="time">
           <time>
            <hour>8</hour>
            <minute>21</minute>
            <second>28</second>
           </time>
          </property>
          <property name="maximumDateTime">
           <datetime>
            <hour>23</hour>
            <minute>59</minute>
            <second>59</second>
            <year>3000</year>
            <month>12</month>
            <day>31</day>
           </datetime>
          </property>
          <property name="minimumDateTime">
           <datetime>
            <hour>0</hour>
            <minute>0</minute>
            <second>0</second>
            <year>1763</year>
            <month>9</month>
            <day>14</day>
           </datetime>
          </property>
          <property name="minimumDate">
           <date>
            <year>1763</year>
            <month>9</month>
            <day>14</day>
           </date>
          </property>
          <property name="currentSection">
           <enum>QDateTimeEdit::YearSection</enum>
          </property>
          <property name="displayFormat">
           <string>yyyy-MM-dd HH:mm:ss</string>
          </property>
          <property name="calendarPopup">
           <bool>false</bool>
          </property>
          <property name="currentSectionIndex">
           <number>0</number>
          </property>
          <property name="timeSpec">
           <enum>Qt::LocalTime</enum>
          </property>
         </widget>
        </item>
        <item row="0" column="3">
         <widget class="QLabel" name="LabDateTime">
          <property name="text">
           <string>字符串显示</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignCenter</set>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </item>
     <item>
      <widget class="QGroupBox" name="groupBox">
       <property name="title">
        <string>定时器</string>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <layout class="QGridLayout" name="gridLayout_2">
          <item row="0" column="0" colspan="2">
           <widget class="QPushButton" name="btnStart">
            <property name="text">
             <string>开始</string>
            </property>
           </widget>
          </item>
          <item row="0" column="2" colspan="2">
           <widget class="QPushButton" name="btnStop">
            <property name="enabled">
             <bool>false</bool>
            </property>
            <property name="text">
             <string>停止</string>
            </property>
           </widget>
          </item>
          <item row="1" column="0">
           <widget class="QLabel" name="label_4">
            <property name="text">
             <string>定时周期</string>
            </property>
           </widget>
          </item>
          <item row="1" column="1" colspan="2">
           <widget class="QSpinBox" name="spinBoxIntv">
            <property name="suffix">
             <string> ms</string>
            </property>
            <property name="maximum">
             <number>999999</number>
            </property>
            <property name="value">
             <number>1000</number>
            </property>
           </widget>
          </item>
          <item row="1" column="3" colspan="2">
           <widget class="QPushButton" name="btnSetIntv">
            <property name="text">
             <string>设置周期</string>
            </property>
           </widget>
          </item>
          <item row="1" column="5">
           <spacer name="horizontalSpacer">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>40</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item row="0" column="5">
           <widget class="QLabel" name="LabElapsTime">
            <property name="text">
             <string>流逝时间</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
           <widget class="QLCDNumber" name="LCDHour">
            <property name="smallDecimalPoint">
             <bool>false</bool>
            </property>
            <property name="digitCount">
             <number>2</number>
            </property>
            <property name="value" stdset="0">
             <double>10.000000000000000</double>
            </property>
            <property name="intValue" stdset="0">
             <number>10</number>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QLCDNumber" name="LCDMin">
            <property name="digitCount">
             <number>2</number>
            </property>
            <property name="intValue" stdset="0">
             <number>26</number>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QLCDNumber" name="LCDSec">
            <property name="digitCount">
             <number>2</number>
            </property>
            <property name="intValue" stdset="0">
             <number>35</number>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <widget class="QProgressBar" name="progressBar">
          <property name="value">
           <number>10</number>
          </property>
          <property name="textVisible">
           <bool>true</bool>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </item>
    </layout>
   </item>
   <item>
    <layout class="QVBoxLayout" name="verticalLayout_2">
     <item>
      <widget class="QGroupBox" name="groupBox_3">
       <property name="title">
        <string>日历选择</string>
       </property>
       <layout class="QGridLayout" name="gridLayout_3">
        <item row="0" column="1">
         <widget class="QLineEdit" name="editCalendar"/>
        </item>
        <item row="1" column="0" colspan="2">
         <widget class="QCalendarWidget" name="calendarWidget">
          <property name="gridVisible">
           <bool>false</bool>
          </property>
         </widget>
        </item>
        <item row="0" column="0">
         <widget class="QLabel" name="label_5">
          <property name="text">
           <string>选择的日期:</string>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </item>
     <item>
      <spacer name="verticalSpacer">
       <property name="orientation">
        <enum>Qt::Vertical</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>
         <width>20</width>
         <height>40</height>
        </size>
       </property>
      </spacer>
     </item>
     <item>
      <widget class="QPushButton" name="btnClose">
       <property name="text">
        <string>退  出</string>
       </property>
      </widget>
     </item>
     <item>
      <spacer name="verticalSpacer_2">
       <property name="orientation">
        <enum>Qt::Vertical</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>
         <width>20</width>
         <height>40</height>
        </size>
       </property>
      </spacer>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections>
  <connection>
   <sender>btnClose</sender>
   <signal>clicked()</signal>
   <receiver>Dialog</receiver>
   <slot>close()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>650</x>
     <y>338</y>
    </hint>
    <hint type="destinationlabel">
     <x>397</x>
     <y>206</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>

 

标签:QStringLiteral,QT,setObjectName,DateTime,groupBox,翻书,Dialog,gridLayout,new
来源: https://www.cnblogs.com/kanbuxiaqu/p/15686018.html