QTime QLCDNumber电子时钟
2016-12-02 21:49
309 查看
#ifndef DIALOG_H #define DIALOG_H #include #include #include #include class Dialog : public QLCDNumber { Q_OBJECT public: Dialog(QWidget *parent = 0); ~Dialog(); void mousePressEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *); public slots: void showTime(); private: QPoint dragPosition; //保存鼠标左上角偏移量 bool showColon; //用来显示时间是否显示 }; #endif // DIALOG_H #include "dialog.h" #include #include Dialog::Dialog(QWidget *parent) : QLCDNumber(parent) { QPalette p = palette(); p.setColor(QPalette::Window,Qt::magenta); setPalette(p); //设置背景 setDigitCount(8); setWindowFlags(Qt::FramelessWindowHint);//设置一个没有边框的窗体 //setWindowOpacity(0.5); QTimer *timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(showTime())); timer->start(1000); showTime(); showColon = true; resize(150,60); } Dialog::~Dialog() { } void Dialog::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { dragPosition = event->globalPos() - frameGeometry().topLeft(); //鼠标相对于时钟窗体左上角的偏移位置 event->accept(); } if(event->button() == Qt::RightButton) { close(); } } void Dialog::mouseMoveEvent(QMouseEvent *event) { if(event->buttons() &Qt::LeftButton) { move(event->globalPos() -dragPosition); event->accept(); } } void Dialog::showTime() { QTime time = QTime::currentTime();//获得当前时间 QString text = time.toString("hh:mm:ss"); if(showColon) { text[2]=':'; text[5]=':'; showColon=false; } else { text[2]=' '; text[5]=' '; showColon = true; } display(text); } #include "dialog.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; w.show(); return a.exec(); }
相关文章推荐
- Qt-LCD电子时钟
- vb6.0做LCD电子时钟
- LCD电子时钟
- Qt之对话框设计——电子时钟
- [TPYBoard - Micropython之会python就能做硬件 3] 制作电子时钟
- 可调闹钟lcd时钟
- C语言实现电子时钟
- Javascript 电子时钟源码
- mipi LCD 的CLK时钟频率与显示分辨率及帧率的关系
- 手把手教你:用Qt做一个漂亮的电子时钟(纯代码)
- 单片机课程设计——《基于AT89S52单片机和DS1302时钟芯片的电子时钟(可蓝牙校准)》
- 51汇编做的电子时钟
- 【电子基础】液晶显示器原理·LCD驱动基础
- 用C做的电子时钟程序
- 单片机时钟程序(9)lcd1602.h
- cocos2dx创建电子时钟
- 用单片机定时器和数码管实现的电子时钟
- date制作电子时钟
- 电子时钟
- jquery模拟LCD 时钟