QT版用QLCDnumber顯示時間
/*基於qt5.7
*無需ui介面
*資料是百度和自幾學到的,不多
*僅供參考
*不喜隨便噴,反正我也不看,哈啊啊、
*/
//首先是dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLCDNumber>
#include <QTime>
#include <QTimer>
#include <QPalette>
#include <QVBoxLayout>
#include <QHBoxLayout>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
public slots:
void showTime();
private:
Ui::Dialog *ui;
QLCDNumber *time;
QTime tim;
QTimer *timer;
};
#endif // DIALOG_H
//接著是dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
resize(200,200); //設定生成介面的大小,可以拖邊框改變介面大小
time = new QLCDNumber(this);
time->setDigitCount(8); //設定lcd裡面的個數,格式是hh:mm:ss,總的是八個。所以設定為8
time->setFixedSize(80, 60); //設定大小
time->setPalette(Qt::cyan); //設定顏色
QVBoxLayout *vbox = new QVBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout;
vbox->addWidget(time);
hbox->addLayout(vbox);
setLayout(hbox); //設定佈局,將lcd空間放到中間
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime())); //用一個定時訊號來更改時間
timer->start(500); //啟動定時
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::showTime()
{
tim = QTime::currentTime(); //獲取當地時間
QString timestr = tim.toString("hh:mm:ss"); //設定時間格式
time->display(timestr); //顯示時間
}
//mian.cpp
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
相關文章
- Qt 時間顯示QT
- QT介面顯示實時時間QT
- QT4 用QLabel實時顯示時間QT
- QT學習 實時顯示時間QT
- Qt實時顯示系統時間QT
- QT顯示當前日期時間QT
- Qt設計:時間顯示(QTimer)QT
- QT實現動態顯示系統時間QT
- Qt QDate QTime顯示當前系統時間QT
- qt-實時顯示本地時間、以及QDateTime的使用QT
- qt中實現實時的顯示當前時刻的時間QT
- Qt中使用QLabel顯示時間的兩種方法QT
- Qt學習(5)獲取當前系統時間-實時顯示當前時間QT
- QT時鐘控制元件顯示QT控制元件
- Qt:通過QLabel控制元件來顯示實時日期時間QT控制元件
- Qt中利用定時器QTimer實時顯示當前日期和時間QT定時器
- Qt中利用定時器QTimer準實時顯示當前日期和時間QT定時器
- js時間顯示設定JS
- 顯示oracle執行時間Oracle
- 【Qt】UI顯示中文QTUI
- android 顯示當前時間(EEEE)顯示星期幾Android
- linux 終端顯示時間Linux
- asp.net 時間顯示格式ASP.NET
- QT居中螢幕顯示QT
- qt視窗居中顯示QT
- Qt之彈出介面顯示在父視窗中間QT
- javascript實時顯示時間程式碼例項JavaScript
- asp.net 中實時顯示本地時間ASP.NET
- javaScript動態顯示當前時間JavaScript
- Qt中顯示OpenCV的IplImageQTOpenCV
- win10時間顯示秒怎麼設定_win10時間顯示秒如何調出Win10
- 為什麼ls-l時,有些檔案顯示日期,有些顯示時間?(轉)
- 帶有星期的時間實時顯示程式碼
- 自定義 RMAN 顯示的日期時間格式
- 設定RMAN顯示的日期時間格式
- 修改Windows工作列的時間顯示(轉)Windows
- Qt 設定視窗居中顯示QT
- Qt中在按鈕上顯示字元'&'QT字元