2.時鐘視窗
3.執行效果圖
簡介:
1.主視窗
menu.**件:
#ifndef menu_h
#define menu_h
#include #include #include class menu : public qwidget
;#endif // menu_h
menu.cpp檔案:#include "menu.h"
#include #include #include menu::menu(qwidget *parent) : qwidget(parent)
void menu::send_t() //設定
void menu::send_s() //顯示
2.時鐘視窗
widget.**件:
#ifndef widget_h
#define widget_h
#include "menu.h"
#include #include //繪圖事件
#include namespace ui
class widget : public qwidget
;#endif // widget_h
widget.cpp檔案:#include "widget.h"
#include "ui_widget.h"
#include #include widget::widget(qwidget *parent) :
qwidget(parent),
ui(new ui::widget)
void widget::send_s() //顯示鐘錶
void widget::get_t(int h1,int m1,int s1)
void widget::timerevent(qtimerevent *event)
if(m == 5)
if(m == 60)
if(h == 12)
qstring ss = qstring::number(s);
qstring sm = qstring::number(m);
int h = h / 5;
qstring sh = qstring::number(h);
t = sh + ":" + sm + ":" +ss;
qdebug()
/* 移動畫家 */
painter->translate(this->width()/2,this->height()/2);
/* 畫鍾 */
qrectf target(-(this->width()/2),-(this->height()/2), this->width(), this->width());
qrectf source(0,0, this->width(), this->height());
qpixmap pixmap(":/new/prefix1/time1.png");
painter->drawpixmap(target, pixmap, source);
/* 畫秒針 */
qrectf target_s(0,5,200, 220);
qrectf source_s(0,0, this->width(),this->height());
qpixmap pixmap_s(":/new/prefix1/time_s.png");
painter->rotate(s*6+180); //定時旋轉秒針
painter->drawpixmap(target_s, pixmap_s, source_s);
/* 畫分針 */
qrectf target_m(-5,-5,200, 220);
qrectf source_m(0,0, this->width(), this->height());
qpixmap pixmap_m(":/new/prefix1/time_m.png");
painter->rotate(-(s*6+180)); //移動回原位
painter->rotate(m*6+180); //旋轉分針
painter->drawpixmap(target_m, pixmap_m, source_m);
/* 畫時針 */
qrectf target_h(-7,-7,200, 220);
qrectf source_h(0,0, this->width(), this->width());
qpixmap pixmap_h(":/new/prefix1/time_h.png");
painter->rotate(-(m*6+180)); //移動回原位
painter->rotate((h*6)+180); //旋轉分針
painter->drawpixmap(target_h, pixmap_h, source_h);
painter->rotate(-(h*6+180));
painter->drawtext(-50,0,100,50,qt::aligncenter, t); //數字時鐘
painter->rotate(h*6+180);
update();
}widget::~widget()
3.執行效果圖
tkinter實現電子時鐘
一 import tkinter import threading import datetime import time tkinter.tk overrideredirect true 不顯示標題欄 attributes alpha 0.9 半透明 attributes topmost 1 總是...
用html實現電子時鐘
animation屬性類似於transition,都屬於隨著時間改變元素的屬性值。其主要的區別在於 transition需要觸發乙個時間才會隨著時間而改變css屬性。animation在不需要觸發事件的情況下,也會隨著時間而改變css樣式。1.動畫不需要事件觸發,過渡需要。2.過渡只有一組 開始的狀...
JS 電子時鐘
思路 獲取當前時間的時間物件 從時間物件中獲取當前的時間資訊,寫入到頁面中 注意 獲取的月份是從0開始的 星期,0是週日,還需要將數值轉化為漢字 d div d.innerhtml nowtime setinterval function 1000 建立當前時間物件 var d newdate 獲取...