⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digiclock.cpp

📁 linux窗口程序设计一书的第三章代码-对话框进阶,希望对大家有用
💻 CPP
字号:
#include "digiclock.h"

DigiClock::DigiClock(QWidget *parent)
	: QLCDNumber(parent)
{
    QPalette p = palette();
    p.setColor(QPalette::Window,Qt::blue);
    setPalette(p);
    
    setWindowFlags(Qt::FramelessWindowHint);

    setWindowOpacity(0.5);
    
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
    timer->start(500);

    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 * e)
{
    if (e->button() == Qt::LeftButton)
    {
    	dragPosition = e->globalPos() - frameGeometry().topLeft();
    	e->accept();
    }
    if (e->button() == Qt::RightButton)
    {
    	close();
    }    
}

void DigiClock::mouseMoveEvent(QMouseEvent * e)
{
    if (e->buttons() & Qt::LeftButton)
    {
    	move(e->globalPos() - dragPosition);
    	e->accept();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -