Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use QT5 to realize a clock Desktop on Windows system

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use QT5 to achieve a clock desktop on the Windows system", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use QT5 on the Windows system to achieve a clock desktop" bar!

Introduction

This is a simple clock operation interface. The structure of the project is shown in the figure. It mainly contains a header file: * * analogclock.h * * and two source files: * * analogclock.cpp main.cpp * *.

Implementation code clock.proQT + = core guigreaterThan (QT_MAJOR_VERSION, 4): QT + = widgetsCONFIG + = cymbals You can make your code fail to compile if it uses deprecated APIs.# In order to do so Uncomment the following line.#DEFINES + = QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES + =\ main.cpp\ analogclock.cppHEADERS + =\ analogclock.h# Default rules for deployment.qnx: target.path = / tmp/$$ {TARGET} / binelse: UnixPartition Android: target.path = / opt/$$ {TARGET} / binbinisEmpty (target.path): INSTALLS + = targetanalogclock.h#ifndef ANALOGCLOCK_H#define ANALOGCLOCK_H#include class AnalogClock: public QWidget {Q_OBJECTpublic: AnalogClock (QWidget * parent=0) Protected: void paintEvent (QPaintEvent * event) override;}; # endif / / WIDGET_Hanalogclock.cpp#include # include "analogclock.h" AnalogClock::AnalogClock (QWidget * parent): QWidget (parent) {QTimer * timer = new QTimer (this); / / instance a QTimer-like connect (timer, SIGNAL (timeout ()), this, SLOT (update (); / / Monitoring whether the timeout () signal is issued / / timeout (): This signal is emitted when the timer times out. / / indicates that the timer sends a signal, that is, the following delay timer sends the signal timer- > start (1000); / / sets the delay of 1 s / * * for a function * void QTimer::start (int msec) * Starts or restarts the timer with a timeout interval of msec milliseconds. * If the timer is already running, it will be stopped and restarted. * If singleShot is true, the timer will be activated only once. * the unit is millisecond, which means that every second a signal is set * / setWindowTitle (tr ("AnalogClock")); / / void setWindowTitle (const QString &) resize (200,200); / / initial value size} void AnalogClock::paintEvent (QPaintEvent *) {/ * repaint () or update () was invoked, * the widget was obscured and has now been uncovered, or * many other reasons. * * / static const QPoint hourHand [3] = {QPoint (7,8), QPoint (- 7,8), QPoint (0,-40)}; / / Triangle static const QPoint minuteHand [3] = {QPoint (7,8), QPoint (- 7,8), QPoint (0,-60)} / / triangular static const QPoint secondHand for minute hand drawing static const QPoint secondHand [3] = {QPoint (7dag8), QPoint (- 7recover8), QPoint (0memently90)}; / / triangular QColor hourColor (127,0,127) for second hand drawing; QColor minuteColor (0127,127,191); / / QColor::QColor (int r, int g, int b, int a = 255) an indicates transparency QColor secondColor (220,20,60100) / / draw color and transparency for each graphic int side = qMin (width (), height ()); / / I think the purpose of this sentence is to find the minimum mark for the drawing of the coordinate system QTime time = QTime::currentTime (); qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report