1.IDE:QTCreator
2.实验:
3.记录
4.代码
cpp
#include "widget.h"
#include "ui_widget.h"
#include <QDateTime>
#include <QCalendar>
#include <QCalendarWidget>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_dial_valueChanged(int value) //当旋钮改变值时
{
ui->show_dialvalue->display(value);
}
void Widget::on_get_DateTime_pb_clicked() //获取日期时间按钮按下时
{
QDateTime datetime = QDateTime::currentDateTime();
ui->time_hour->display(datetime.toString("hh"));
ui->time_minu->display(datetime.toString("mm"));
ui->time_seco->display(datetime.toString("ss"));
ui->Datetime_tx->setText(datetime.toString("yyyy-MM-dd hh:mm:ss"));
ui->timeEdit->setTime(datetime.time());
}
void Widget::on_calendarWidget_selectionChanged() //选中日期改变时
{
QDate date= ui->calendarWidget->selectedDate();
ui->calender_tx->setText(date.toString("yyyy年MM月dd日"));
}
void Widget::on_settime_pb_clicked()
{
QString time_string= ui->settime_tx->text();
QTime time= QTime::fromString(time_string,"hh:mm,ss");
ui->timeEdit->setTime(time);
}