我做了一个电子钟,但是无法显示,请各路高手都来指点指点
"DIYClock.h"
DIYClock::DIYClock(QWidget *parent)
:QLCDNumber(parent)
{
QPalette p=palette();
p.setColor(QPalette::Window,Qt::green);
setPalette(p);
setWindowFlags(Qt::FramelessWindowHint);
setWindowOpacity(0.5);
QTimer *timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
timer->start(1000);
showTime();
resize(150,60);
showColon=true;
}
void DIYClock::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 DIYClock::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)
{
dragPosition=e->globalPos()-frameGeometry().topLeft();
e->accept();
}
if(e->button()==Qt::RightButton)
{
close();
}
}
void DIYClock::mouseMoveEvent(QMouseEvent *e)
{
if(e->buttons()&Qt::LeftButton)
{
move(e->globalPos()-dragPosition);
e->accept();
}
}
mainWindow.cpp
mainWindow::mainWindow(QWidget *parent,Qt::WindowFlags f)
:QWidget(parent,f)
{
clockButton=new customizeButton(tr("电子钟"),this);
clockButton->setFlat(FALSE);
QColor clockButtonColor1(Qt::darkRed);
QColor clockButtonColor2(Qt::black);
QColor clockButtonColor3(Qt::red);
clockButton->setColor(clockButtonColor1);
clockButton->setShadow(clockButtonColor2);
clockButton->setHighlight(clockButtonColor3);
clockButton->setRoundness(20);
clockButton->setOpacity(0.65);
clockButton->setToolTip(tr("电子钟显示/隐藏"));
QObject::connect(clockButton,SIGNAL(clicked()),this,SLOT(chooseClock()));
}
void mainWindow::chooseClock()
{
DIYClock *clock=new DIYClock(this);
clock->showTime();
}