• qt小例子:倒着走的时钟


    效果图,显示当天剩余的时间

    上代码:

    使用了qt form

    代码

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>myWidget</class>
     <widget class="QWidget" name="myWidget">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>500</width>
        <height>106</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>myWidget</string>
      </property>
      <widget class="QLabel" name="label">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>-10</y>
         <width>491</width>
         <height>111</height>
        </rect>
       </property>
       <property name="font">
        <font>
         <family>Algerian</family>
         <pointsize>72</pointsize>
        </font>
       </property>
       <property name="text">
        <string>99:99:99</string>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>

    关键代码:

    #include "mywidget.h"
    #include "ui_mywidget.h"
    #include <QTimer>
    #include <QTime>
    #include <stdio.h>
    
    myWidget::myWidget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::myWidget)
    {
        ui->setupUi(this);
        QTimer *timer = new QTimer(this);
        connect(timer, &QTimer::timeout, this, &myWidget::showTime);
        ui->label->setText("88:99:77");
        timer->start(1000);
    
        showTime();
    }
    
    void myWidget::showTime()
    {
        char  time_str[10]={0};
        int h,m,s;
    
        QTime time = QTime::currentTime();
    
        h=23-time.hour();
        m=59-time.minute();
        s=59-time.second();
        sprintf(time_str,"%02d:%02d:%02d",h,m,s);
        QString str = QString(QLatin1String(time_str));
        ui->label->setText(str);
    }
    
    myWidget::~myWidget()
    {
        delete ui;
    }
    他只是向前航行,脚下是沉静碧蓝的大海,而头顶是金色的太阳。
  • 相关阅读:
    C#聊天+五子棋
    分页
    用户自定义控件(.ascx)
    一、Text To Speech
    验证码
    白话学习MVC(三)页面周期二
    二、Speech To Text
    微软云体验营 北京站 ,4月27日免费开营啦!名额有限速速报名!
    Windows 8 页面应用测试(2)
    《Windows 8应用开发权威指南》图书开始在网络上预售
  • 原文地址:https://www.cnblogs.com/bliss-/p/14115060.html
Copyright © 2020-2023  润新知