DigiClock::DigiClock(QWidget *parent)
: QLCDNumber(parent)
{
//设置时钟背景
QPalette p = palette();<br /> //设置调色板颜色 QPalette::Window 设置背景色
p.setColor(QPalette::Window, Qt::blue);<br /> //设置当前界面调色板
setPalette(p);<br /> //设置窗体标识 此处设置窗体无面板边框和标题栏
setWindowFlags(Qt::FramelessWindowHint);<br /> //设置窗体透明度0.5
setWindowOpacity(0.5);<br /> //创建qtimer类
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &DigiClock::showTime);<br /> //以1000ms为周期启动定时器
timer->start(1000);
showTime();
resize(500, 200);<br /> //是否显示冒号
showColon = true;
}<br />//槽函数</pre>
<pre>void DigiClock::showTime()
{
QTime time = QTime::currentTime();
QString str = time.toString("hh:mm");
if (showColon)
{
str[2] = ':';
showColon = false;
}
else
{
str[2] = ' ';
showColon = true;
}
display(str);
}```
标签:设置,Qpalette,QTime,showColon,DigiClock,nbsp,str,qwidget
From: https://www.cnblogs.com/cwb8023/p/17275370.html