日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

QT学习:QTime类

發布時間:2024/9/30 c/c++ 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QT学习:QTime类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

QTime的currentTime():用于獲取當前的系統時間;
QTime 的toString():用于將獲取的當前時間轉換為字符串類型。
為了便于顯示,toString()函數的參數需指定轉換后時間的顯示格式。
顯示格式有如下幾種:
(1)H/h: 小時(若使用H表示小時,則無論何時都以24小時制顯示小時;若使用h表示小時,則當同時指定AM/PM時,采用12 小時制顯示小時,其他情況下仍采用24小時制進行顯示)
(2)m:分
(3)s:秒
(4)AP/A:顯示AM或PM
(5)Ap/a:顯示am或pm
下面以代碼形式介紹具體用法:
頭文件:

#ifndef DIGICLOCK_H #define DIGICLOCK_H #include<QLCDNumber> #include<QTime> #include<QTimer>class DigiClock : public QLCDNumber { public:DigiClock(QWidget *parent=0);void mousePressEvent(QMouseEvent *);void mouseMoveEvent(QMouseEvent *); public slots:void showTime(); private:QPoint dragPosition;bool showColon; }; #endif // DIGICLOCK_H

cpp文件:

#include "digiclock.h" #include<QMouseEvent>DigiClock::DigiClock(QWidget *parent):QLCDNumber(parent) {QPalette p=palette();p.setColor(QPalette::Window,Qt::blue);//設置窗體的顏色setPalette(p);//將調色板得以運用setWindowFlags(Qt::FramelessWindowHint);setWindowOpacity(0.5);//showTime();QTimer *timer=new QTimer(this);connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));timer->start(1000);showColon=true;showTime();resize(150,60);//showColon=true;}void DigiClock::showTime() {QTime time=QTime::currentTime();QString text=time.toString("hh:mm");if(showColon){text[2]=':';showColon=false;}else{text[2]=';';showColon=true;}display(text); }void DigiClock::mousePressEvent(QMouseEvent *event) {if(event->button()==Qt::LeftButton){dragPosition=event->globalPos()-frameGeometry().topLeft();event->accept();}if(event->button()==Qt::RightButton){close();} } void DigiClock::mouseMoveEvent(QMouseEvent *event) {if(event->buttons()&Qt::LeftButton){move(event->globalPos()-dragPosition);event->accept();} }

main函數的內容為:

#include "dialog.h" #include <QApplication> #include"digiclock.h"int main(int argc, char *argv[]) {QApplication a(argc, argv);DigiClock clock;clock.show();//Dialog w;// w.show();return a.exec(); }

展示的結果如下圖所示:

總結

以上是生活随笔為你收集整理的QT学习:QTime类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。