Solved A Clock isn't show hours,who can tell me what has happened? it's show like this format MM:SS
-
A Clock isn't show hour,who can tell me what has happened?
i just want it show HH:MM:SS//digiclock.h #ifndef DIGICLOCK_H #define DIGICLOCK_H #include<QLCDNumber> class DigiClock : public QLCDNumber { Q_OBJECT public: DigiClock(QWidget * parent=0); void mousePressEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *); private slots: void showTime();//显示当前时间 private: QPoint dragPosition;//保存鼠标点相对电子时钟窗体左上角的偏移值 bool showColon;//用于显示时间是否显示" : " }; #endif // DIGICLOCK_H //digiclock.cpp #include "digiclock.h" #include<QTimer> #include<QTime> #include<QMouseEvent> #include<QPalette> DigiClock::DigiClock(QWidget * parent): QLCDNumber(parent) { /*设置时钟背景*/ QPalette p=palette(); p.setColor(QPalette::Window,Qt::yellow); setPalette(p); setWindowFlags(Qt::FramelessWindowHint);//?//设置窗体标示,此处设置为一个没有面板边框和标题栏的窗体 setWindowTitle(tr("电子时钟")); setWindowOpacity(0.5);//设置窗体透明度 QTimer *timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(showTime())); timer->start(1000); showTime(); resize(350,60); showColon=true; } void DigiClock::mousePressEvent(QMouseEvent * event) { if(event->button()==Qt::LeftButton) { dragPosition=event->globalPos()-frameGeometry().topLeft(); event->accept(); } if(event->button()==Qt::RightButton) { close(); } } void DigiClock::mouseMoveEvent(QMouseEvent *event) { if(event->buttons()&Qt::LeftButton) { move(event->globalPos()-dragPosition); event->accept(); } } void DigiClock::showTime() { QTime time=QTime::currentTime(); QString text=time.toString("hh:mm:ss"); if(showColon) { text[2]=':'; showColon=false; } else { text[2]=' '; showColon=true; } display(text); }
-
-
@raven-worx You are looking at the wrong function doc. See here. Column is one of the authorised char.
@konalo You should start from the Digital clock example without modification and then build from it.
-
@SGaist what's your mean? ??_??
-
@SGaist said in A Clock isn't show hours,who can tell me what has happened? it's show like this format MM:SS:
@raven-worx You are looking at the wrong function doc. See here. Column is one of the authorised char.
oh i was looking at the 4.8 docs... haven noticed.
-
@raven-worx hum, but i got hh:mm or mm:ss ,when i set the format hh:mm and mm:ss
,but when i set the text format hh:mm:ss , it's show me mm:ss -
@konalo @raven-worx @SGaist
got it , in doc detailed description of QLCDNumber "The QLCDNumber widget displays a number with LCD-like digits.
It can display a number in just about any size. It can display decimal, hexadecimal, octal or binary numbers. It is easy to connect to data sources using the display() slot, which is overloaded to take any of five argument types." it only show five by default , addDigiClock::setDigitCount(8);
i got what i want,just HH:MM:SS
-
@raven-worx, it's really just the wrong overload you were looking at ;)
@konalo Great ! Thanks for sharing your solution.
-
@SGaist said in A Clock isn't show hours,who can tell me what has happened? it's show like this format MM:SS:
@raven-worx, it's really just the wrong overload you were looking at ;)
no, compare the Qt 4.8 docs and the Qt 5 docs of QLCDNumber's
display(QString)
method. They have changed semantically. -
My bad, it was in the detailed description for Qt 4.