Create a QT clock

Source: Internet
Author: User

1. Use of qlcdnumber

# Ifndef mainwindow_h
# Define mainwindow_h

# Include <qmainwindow>

# Include <qtime>
# Include <qtimer>
# Include <qmessagebox>
# Include <qtgui/qlcdnumber>

Namespace UI {
Class logo;
}

Class logo: Public qmainwindow
{
Q_object

Public:
Explicit logo (qwidget * parent = 0 );
~ Logo ();
Qlcdnumber * LCD;
Private slots: // keyword
Void Showtime ();

PRIVATE:
Ui: logo * UI;
Qtimer * timer;
};

# Endif // mainwindow_h

# Include "logo. H"
# Include "ui_main1_1_h"

Logo: logo (qwidget * parent ):
Qmainwindow (parent ),
UI (new UI: logo)
{
UI-> setupui (this );

Qt: windowflags new_flags = 0;
New_flags = QT: Window | QT: framelesswindowhint;
Setwindowflags (new_flags );
Setgeometry (0, 0, 480,272 );

Qpixmap background;
Background = qpixmap ("D:/qtsdk/qtcreator/newproject/jiemian.jpg ");

Qpalette palette;
Palette. setbrush (qwidget: backgroundrole (), qbrush (background ));
Setpalette (palette );

Timer = new qtimer (this );
// Timer-> Start (2000 );
Connect (timer, signal (timeout (), this, slot (mylogo ));
LCD = new qlcdnumber (this );
LCD-> setsegmentstyle (qlcdnumber: filled );
LCD-> setnumdigits (8); // you can specify the number of digits to display.
Qtimer * timer = new qtimer (this );
Connect (timer, signal (timeout (), this, slot (Showtime ()));
Timer-> Start (1000 );
Showtime ();
Setwindowtitle (TR ("Digital Clock "));
LCD-> resize );
}

Logo ::~ Logo ()
{
Delete UI;
}

Void logo: Showtime ()
{
Qtime time = qtime: currenttime ();
Qstring text = time. tostring ("HH: mm: SS ");
If (time. Second () % 2) = 0)
{
Text [2] = '';
Text [5] = '';
}
LCD-> display (text );
}

2. Image Display

 

Void login: showdate ()
{
Qdate date = qdate: currentdate ();
Qstring text_date = date. tostring ("yyyy/mm/dd ddd ");
// Label_date-> settext (text_date );
UI-> yearh1-> setpixmap (qpixmap (geticonname (text_date [0]);
UI-> year2-> setpixmap (qpixmap (geticonname (text_date [1]);
UI-> year3-> setpixmap (qpixmap (geticonname (text_date [2]);
UI-> year4-> setpixmap (qpixmap (geticonname (text_date [3]);
// UI-> Xie-> setpixmap (qpixmap (geticonname (text_date [4]);
UI-> month1-> setpixmap (qpixmap (geticonname (text_date [5]);
UI-> mon22-> setpixmap (qpixmap (geticonname (text_date [6]);
// UI-> xie1-> setpixmap (qpixmap (geticonname (text_date [7]);
UI-> day1-> setpixmap (qpixmap (geticonname (text_date [8]);
UI-> day2-> setpixmap (qpixmap (geticonname (text_date [9]);
}

Void login: Showtime ()
{
Qtime time = qtime: currenttime ();
Qstring text = time. tostring ("HH: mm: ss ");
UI-> hourh-> setpixmap (qpixmap (geticonname (Text [0]);
UI-> hourl-> setpixmap (qpixmap (geticonname (Text [1]);
// UI-> mouhao-> setpixmap (qpixmap (geticonname (Text [2]);
UI-> Minh-> setpixmap (qpixmap (geticonname (Text [3]);
UI-> minl-> setpixmap (qpixmap (geticonname (Text [4]);
// UI-> maohao1-> setpixmap (qpixmap (geticonname (Text [5]);
UI-> Sech-> setpixmap (qpixmap (geticonname (Text [6]);
UI-> secl-> setpixmap (qpixmap (geticonname (Text [7]);
// Label_time-> settext (text_time );
}

Qstring login: geticonname (qchar X)
{
Return (qstring (":/file/images/") + x + qstring (". GIF "));
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.