Qt 绘制电池

用Qt实现显示电池电量 在项目设置中,指定项目的名称和保存位置,并点击"下一步"。然后,再拖放一个标签作为显示电量的控件,将其位置调整到"电池电量:"标签的右侧。在Qt Creator的"槽函数"视图中,双击"on_pushButton_clicked()"函数,以便在按钮点击事件中执行一些操作。通过创建一个Qt项目,设计用户界面,使用QSystemTrayIcon类和平台特定的API,我们可以轻松地实现这个功能。通过使用Qt,我们可以轻松地创建一个具有用户界面的应用程序,该应用程序可以读取系统的电池信息并将其显示出来。 阅读详情

实现如下功能:

 * 1. 可设置电池电量,动态切换电池电量变化
 * 2. 可设置电池电量警戒值
 * 3. 可设置电池电量正常颜色和报警颜色
 * 4. 可设置边框渐变颜色
 * 5. 可设置电量变化时每次移动的步长
 * 6. 可设置边框圆角角度/背景进度圆角角度/头部圆角角度
#ifndef BATTERY_H
#define BATTERY_H
#include <QWidget>

class Battery : public QWidget
{
    Q_OBJECT    
    Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
    Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
    Q_PROPERTY(double value READ getValue WRITE setValue)
    Q_PROPERTY(double alarmValue READ getAlarmValue WRITE setAlarmValue)

    Q_PROPERTY(double step READ getStep WRITE setStep)
    Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
    Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
    Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
    Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)

    Q_PROPERTY(QColor borderColorStart READ getBorderColorStart WRITE setBorderColorStart)
    Q_PROPERTY(QColor borderColorEnd READ getBorderColorEnd WRITE setBorderColorEnd)

    Q_PROPERTY(QColor alarmColorStart READ getAlarmColorStart WRITE setAlarmColorStart)
    Q_PROPERTY(QColor alarmColorEnd READ getAlarmColorEnd WRITE setAlarmColorEnd)

    Q_PROPERTY(QColor normalColorStart READ getNormalColorStart WRITE setNormalColorStart)
    Q_PROPERTY(QColor normalColorEnd READ getNormalColorEnd WRITE setNormalColorEnd)

public:
    explicit Battery(QWidget *parent = 0);
    ~Battery();

protected:
    void paintEvent(QPaintEvent *);
    void drawBorder(QPainter *painter);
    void drawBg(QPainter *painter);
    void drawHead(QPainter *painter);

private slots:
    void updateValue();

private:    
    double minValue;                //最小值
    double maxValue;                //最大值
    double value;                   //目标电量
    double alarmValue;              //电池电量警戒值

    double step;                    //每次移动的步长
    int borderWidth;                //边框粗细
    int borderRadius;               //边框圆角角度
    int bgRadius;                   //背景进度圆角角度
    int headRadius;                 //头部圆角角度

    QColor borderColorStart;        //边框渐变开始颜色
    QColor borderColorEnd;          //边框渐变结束颜色

    QColor alarmColorStart;         //电池低电量时的渐变开始颜色
    QColor alarmColorEnd;           //电池低电量时的渐变结束颜色

    QColor normalColorStart;        //电池正常电量时的渐变开始颜色
    QColor normalColorEnd;          //电池正常电量时的渐变结束颜色

    bool isForward;                 //是否往前移
    double currentValue;            //当前电量
    QRectF batteryRect;             //电池主体区域
    QTimer *timer;                  //绘制定时器

public:    
    double getMinValue()            const;
    double getMaxValue()            const;
    double getValue()               const;
    double getAlarmValue()          const;

    double getStep()                const;
    int getBorderWidth()            const;
    int getBorderRadius()           const;
    int getBgRadius()               const;
    int getHeadRadius()             const;

    QColor getBorderColorStart()    const;
    QColor getBorderColorEnd()      const;

    QColor getAlarmColorStart()     const;
    QColor getAlarmColorEnd()       const;

    QColor getNormalColorStart()    const;
    QColor getNormalColorEnd()      const;

    QSize sizeHint()                const;
    QSize minimumSizeHint()         const;

public Q_SLOTS:
    //设置范围值
    void setRange(double minValue, double maxValue);
    void setRange(int minValue, int maxValue);

    //设置最大最小值
    void setMinValue(double minValue);
    void setMaxValue(double maxValue);

    //设置电池电量值
    void setValue(double value);
    void setValue(int value);

    //设置电池电量警戒值
    void setAlarmValue(double alarmValue);
    void setAlarmValue(int alarmValue);

    //设置步长
    void setStep(double step);
    void setStep(int step);

    //设置边框粗细
    void setBorderWidth(int borderWidth);
    //设置边框圆角角度
    void setBorderRadius(int borderRadius);
    //设置背景圆角角度
    void setBgRadius(int bgRadius);
    //设置头部圆角角度
    void setHeadRadius(int headRadius);

    //设置边框渐变颜色
    void setBorderColorStart(const QColor &borderColorStart);
    void setBorderColorEnd(const QColor &borderColorEnd);

    //设置电池电量报警时的渐变颜色
    void setAlarmColorStart(const QColor &alarmColorStart);
    void setAlarmColorEnd(const QColor &alarmColorEnd);

    //设置电池电量正常时的渐变颜色
    void setNormalColorStart(const QColor &normalColorStart);
    void setNormalColorEnd(const QColor &normalColorEnd);

Q_SIGNALS:
    void valueChanged(double value);
};

#endif // BATTERY_H

 

#pragma execution_character_set("utf-8")

#include "battery.h"
#include "qpainter.h"
#include "qtimer.h"
#include "qdebug.h"

Battery::Battery(QWidget *parent) : QWidget(parent)
{
    minValue = 0;
    maxValue = 100;
    value = 0;
    alarmValue = 30;
    step = 0.5;

    borderWidth = 5;
    borderRadius = 8;
    bgRadius = 5;
    headRadius = 3;

    borderColorStart = QColor(100, 100, 100);
    borderColorEnd = QColor(80, 80, 80);
    alarmColorStart = QColor(250, 118, 113);
    alarmColorEnd = QColor(204, 38, 38);
    normalColorStart = QColor(50, 205, 51);
    normalColorEnd = QColor(60, 179, 133);

    isForward = false;
    currentValue = 0;

    timer = new QTimer(this);
    timer->setInterval(10);
    connect(timer, SIGNAL(timeout()), this, SLOT(updateValue()));
}

Battery::~Battery()
{
    if (timer->isActive()) {
        timer->stop();
    }
}

void Battery::paintEvent(QPaintEvent *)
{
    //绘制准备工作,启用反锯齿
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

    //绘制边框
    drawBorder(&painter);
    //绘制背景
    drawBg(&painter);
    //绘制头部
    drawHead(&painter);
}

void Battery::drawBorder(QPainter *painter)
{
    painter->save();

    double headWidth = width() / 15;
    double batteryWidth = width() - headWidth;

    //绘制电池边框
    QPointF topLeft(borderWidth, borderWidth);
    QPointF bottomRight(batteryWidth, height() - borderWidth);
    batteryRect = QRectF(topLeft, bottomRight);

    painter->setPen(QPen(borderColorStart, borderWidth));
    painter->setBrush(Qt::NoBrush);
    painter->drawRoundedRect(batteryRect, borderRadius, borderRadius);

    painter->restore();
}

void Battery::drawBg(QPainter *painter)
{
    if (value == minValue) {
        return;
    }

    painter->save();

    QLinearGradient batteryGradient(QPointF(0, 0), QPointF(0, height()));
    if (currentValue <= alarmValue) {
        batteryGradient.setColorAt(0.0, alarmColorStart);
        batteryGradient.setColorAt(1.0, alarmColorEnd);
    } else {
        batteryGradient.setColorAt(0.0, normalColorStart);
        batteryGradient.setColorAt(1.0, normalColorEnd);
    }

    int margin = qMin(width(), height()) / 20;
    double unit = (batteryRect.width() - (margin * 2)) / 100;
    double width = currentValue * unit;
    QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin);
    QPointF bottomRight(width + margin + borderWidth, batteryRect.bottomRight().y() - margin);
    QRectF rect(topLeft, bottomRight);

    painter->setPen(Qt::NoPen);
    painter->setBrush(batteryGradient);
    painter->drawRoundedRect(rect, bgRadius, bgRadius);

    painter->restore();
}

void Battery::drawHead(QPainter *painter)
{
    painter->save();

    QPointF headRectTopLeft(batteryRect.topRight().x(), height() / 3);
    QPointF headRectBottomRight(width(), height() - height() / 3);
    QRectF headRect(headRectTopLeft, headRectBottomRight);

    QLinearGradient headRectGradient(headRect.topLeft(), headRect.bottomLeft());
    headRectGradient.setColorAt(0.0, borderColorStart);
    headRectGradient.setColorAt(1.0, borderColorEnd);

    painter->setPen(Qt::NoPen);
    painter->setBrush(headRectGradient);
    painter->drawRoundedRect(headRect, headRadius, headRadius);

    painter->restore();
}

void Battery::updateValue()
{
    if (isForward) {
        currentValue -= step;
        if (currentValue <= value) {
            timer->stop();
        }
    } else {
        currentValue += step;
        if (currentValue >= value) {
            timer->stop();
        }
    }

    this->update();
}

double Battery::getMinValue() const
{
    return this->minValue;
}

double Battery::getMaxValue() const
{
    return this->maxValue;
}

double Battery::getValue() const
{
    return this->value;
}

double Battery::getAlarmValue() const
{
    return this->alarmValue;
}

double Battery::getStep() const
{
    return this->step;
}

int Battery::getBorderWidth() const
{
    return this->borderWidth;
}

int Battery::getBorderRadius() const
{
    return this->borderRadius;
}

int Battery::getBgRadius() const
{
    return this->bgRadius;
}

int Battery::getHeadRadius() const
{
    return this->headRadius;
}

QColor Battery::getBorderColorStart() const
{
    return this->borderColorStart;
}

QColor Battery::getBorderColorEnd() const
{
    return this->borderColorEnd;
}

QColor Battery::getAlarmColorStart() const
{
    return this->alarmColorStart;
}

QColor Battery::getAlarmColorEnd() const
{
    return this->alarmColorEnd;
}

QColor Battery::getNormalColorStart() const
{
    return this->normalColorStart;
}

QColor Battery::getNormalColorEnd() const
{
    return this->normalColorEnd;
}

QSize Battery::sizeHint() const
{
    return QSize(150, 80);
}

QSize Battery::minimumSizeHint() const
{
    return QSize(30, 10);
}

void Battery::setRange(double minValue, double maxValue)
{
    //如果最小值大于或者等于最大值则不设置
    if (minValue >= maxValue) {
        return;
    }

    this->minValue = minValue;
    this->maxValue = maxValue;

    //如果目标值不在范围值内,则重新设置目标值
    //值小于最小值则取最小值,大于最大值则取最大值
    if (value < minValue) {
        setValue(minValue);
    } else if (value > maxValue) {
        setValue(maxValue);
    }

    this->update();
}

void Battery::setRange(int minValue, int maxValue)
{
    setRange((double)minValue, (double)maxValue);
}

void Battery::setMinValue(double minValue)
{
    setRange(minValue, maxValue);
}

void Battery::setMaxValue(double maxValue)
{
    setRange(minValue, maxValue);
}

void Battery::setValue(double value)
{
    //值和当前值一致则无需处理
    if (value == this->value) {
        return;
    }

    //值小于最小值则取最小值,大于最大值则取最大值
    if (value < minValue) {
        value = minValue;
    } else if (value > maxValue) {
        value = maxValue;
    }

    if (value > currentValue) {
        isForward = false;
    } else if (value < currentValue) {
        isForward = true;
    } else {
        this->value = value;
        this->update();
        return;
    }

    this->value = value;
    this->update();
    emit valueChanged(value);
    timer->stop();
    timer->start();
}

void Battery::setValue(int value)
{
    setValue((double)value);
}

void Battery::setAlarmValue(double alarmValue)
{
    if (this->alarmValue != alarmValue) {
        this->alarmValue = alarmValue;
        this->update();
    }
}

void Battery::setAlarmValue(int alarmValue)
{
    setAlarmValue((double)alarmValue);
}

void Battery::setStep(double step)
{
    if (this->step != step) {
        this->step = step;
        this->update();
    }
}

void Battery::setStep(int step)
{
    setStep((double)step);
}

void Battery::setBorderWidth(int borderWidth)
{
    if (this->borderWidth != borderWidth) {
        this->borderWidth = borderWidth;
        this->update();
    }
}

void Battery::setBorderRadius(int borderRadius)
{
    if (this->borderRadius != borderRadius) {
        this->borderRadius = borderRadius;
        this->update();
    }
}

void Battery::setBgRadius(int bgRadius)
{
    if (this->bgRadius != bgRadius) {
        this->bgRadius = bgRadius;
        this->update();
    }
}

void Battery::setHeadRadius(int headRadius)
{
    if (this->headRadius != headRadius) {
        this->headRadius = headRadius;
        this->update();
    }
}

void Battery::setBorderColorStart(const QColor &borderColorStart)
{
    if (this->borderColorStart != borderColorStart) {
        this->borderColorStart = borderColorStart;
        this->update();
    }
}

void Battery::setBorderColorEnd(const QColor &borderColorEnd)
{
    if (this->borderColorEnd != borderColorEnd) {
        this->borderColorEnd = borderColorEnd;
        this->update();
    }
}

void Battery::setAlarmColorStart(const QColor &alarmColorStart)
{
    if (this->alarmColorStart != alarmColorStart) {
        this->alarmColorStart = alarmColorStart;
        this->update();
    }
}

void Battery::setAlarmColorEnd(const QColor &alarmColorEnd)
{
    if (this->alarmColorEnd != alarmColorEnd) {
        this->alarmColorEnd = alarmColorEnd;
        this->update();
    }
}

void Battery::setNormalColorStart(const QColor &normalColorStart)
{
    if (this->normalColorStart != normalColorStart) {
        this->normalColorStart = normalColorStart;
        this->update();
    }
}

void Battery::setNormalColorEnd(const QColor &normalColorEnd)
{
    if (this->normalColorEnd != normalColorEnd) {
        this->normalColorEnd = normalColorEnd;
        this->update();
    }
}

效果图:

QT实现显示电池电量(附完整源码) 阅读详情

相关推荐

QT绘制蓄电池电气图(附完整源码)

QT绘制蓄电池电气图(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 290

qt电池控件设计

效果 h文件(battery.h) #ifndef BATTERY_H #define BATTERY_H /** * 电池电量控件 * 1. 可设置电池电量,动态切换电池电量变化 * 2. 可设置电池电量警戒值 * 3. 可设置电池电量正常颜色和报警颜色 * 4. 可设置边框渐变颜色 * 5. 可设置电量变化时每次移动的步长 * 6. 可设置边框圆角角度/背景进度圆角角度/头部圆角角度 */ #include <QWidget> class Battery : publ

weixin_42887343的博客 2137

Qt绘制的电池电量显示小Demo

qt绘制的简单的电池控件,电量低于阈值时显示电量为红色,大于阈值设置电量为绿色,阈值可设置,简单Demo

QtWidget绘制电池控件

使用QPainter来进行绘制自定义的控件,然后通过QTimer来实现电池控件的电量变化效果,效果图如下:

Thinking777的博客 1296

Qt绘制自定义数字电压表

Qt绘制的自定义电压表,可测电压为0-500v,可自行修改量程和分辨率,源码下载编译

Qt代码实现创建电池控件

Qt代码实现创建电池控件

QT 绘制电池

绘制上下结构的电池#ifndef QMYBATTERY_H #define QMYBATTERY_H#include <QObject> #include <QWidget> #include <QColor>class qMyBattery : public QWidget { Q_OBJECT private: QColor mColorBack=Qt::white;//背景颜色 QColor mColorBorder=Qt::black;//电池边框颜色 QColo

sdfgh4的博客 371

智能驾驶小白必看:MEB低速紧急制动系统的工作原理与传感器配置详解

本文深入解析了MEB低速紧急制动系统的工作原理与传感器配置。该系统作为智能驾驶的关键安全冗余,专为应对停车场、拥堵路段等复杂低速场景设计。文章详细拆解了其如何通过超声波雷达、环视摄像头等传感器融合感知环境,并基于碰撞时间(TTC)等模型进行风险评估与分级制动,最终实现主动防碰撞,是智能驾驶技术实用化的重要体现。

c2d3e4f的博客 1132

QT绘制电池图标(横立,竖立全部包括)

电池电量显示分为横向变化和纵向变化。把电池头和电池边框的比例可以计算一下,我这里是把控件总宽度分成20份,让电池头占一份,其余的都是电池边框(如果你想做纵向的电池就用高度计算)本文实现QT实现绘制电池图标主要是在paintEven中进行绘制,网上历程很多,本文旨在记录总结!电池绘制分为三部分,绘制电池头,绘制电池边框以及绘制电池电量。3.绘制电池电量变化。

weixin_53090658的博客 575

使用VLC库实现视频播放器(WPF版)

使用wpf制作一个视频播放器 一、 LibVLCSharp介绍 LibVLCSharp是基于VideoLAN的LibVLC库的.NET平台的跨平台音频和视频API。它提供了一个全面的多媒体API,可以跨移动、服务器和桌面使用,以呈现视频和输出音频。支持Mono、.NET Framework和.NET核心运行时。在vs工具中,只需要安装截图中得两个nuget包。 二、视频播放器的实现 视频播放器的实现需要用到两个比较nuget包中提供的类,MediaPlayer类。MediaPlayer类型用于控

cangqiongxiaoye的博客 1万+

U24时钟信号上升下降沿出现非单调性--简单分析

交换机U24时钟信号上升下降沿出现非单调性--简单分析

qq_45185504的博客 1132

Qt绘制电池图标源码分享

摘要:这是一个Qt电池控件实现代码,包含CellWidget类定义和实现。该控件通过自定义绘制实现电池图形显示,支持背景色、边框色、电量色和警告色设置,可显示当前电量值、最大值和警告阈值。核心功能包括:1) 使用Q_PROPERTY定义属性接口;2) 通过paintEvent实现电池图形绘制;3) 电量低于阈值时自动切换警告颜色。代码结构清晰,包含完整的属性访问方法和信号槽机制,适合嵌入Qt应用程序中显示电池状态。

本博客分享软硬件一体化开发实战。硬件涵盖 PCB 设计、STM32 等 MCU 底层开发;软件包含 C++、Rust,Qt/QML、PyQt、Slint、TouchGFX、LVGL 各类 GUI 框架。方便软硬件开发者查阅学习。欢迎关注! 712

Windows10 搭建 FTP 服务器

问题: 有这么一个需求,博主需要对班级同学的信息进行收集,同学的信息是一个个的文件, 正常是每个同学将自己的信息打包压缩通过 QQ 或者邮箱方式发送给博主, 博主一个个接收这些压缩包,然后进行解压,再统一放到一个文件夹下, 但是博主觉得这样子实在是太麻烦了,如果某一个同学的信息来回变动,就需要接收很多次,更改很多次, 另外如果消息过多还会产生漏掉某个同学的信息的问题。 解决方法: 如果可以使...

assiduous_me的博客 3966

Qt绘制电池UI

QT绘制电池UI

qq_44896246的博客 678

《SAP FICO系统配置从入门到精通共40篇》030、集成配置:FI与生产计划(PP)的自动科目确定

FI和PP的自动科目确定,本质上是把生产业务翻译成会计语言。翻译规则就藏在那些配置表里。配的时候多想一步:这个业务动作,在财务眼里是什么?是材料消耗?是产出入库?还是工费分摊?想清楚这个,再看配置界面,那些代码就不是天书了。最好的测试方式,是月底关账前,让生产部门跑一遍所有类型的生产订单。配置对不对,业务最知道。

985大学毕业,前某大厂员工,啥都会点的程序员! 575

PD详解—第一章—Type-C连接

Type-C连接 今天大师匈下班比较早,再给大家侃一侃PD,希望大家支持。 PD和Type-c的关系 首先讲一下PD快充的实现步骤,本文主要是Source端(电源),Sink端的差不多也一样,只是策略不同而已。 TypeC连接-->广播电源能力Source capbility(数据交互)->打电压电流->等待其他指令。 所以typec连接是第一步,很多人会从字面意思理解typec连接,这不就是把线给插上去就好了吗? 不知道有没有优秀的同学想到正确答案; 正确答案:typec连接的本质是为

大师匈的博客 1万+

Qt绘制电池进度条示例代码

Qt绘制电池进度条示例代码 去发现同类优质开源项目:https://gitcode.com/ 本项目提供了一个基于Qt5.14.2的电池进度条绘制示例,适用于初学者学习和参考。以下为示例代码的详细说明: 资源文件简介 标题:Qt绘制电池进度条(paintEvent) 描述:本项目实现了一个电池进度条,并根据电量百分比添加了正常颜色与警示颜色的判断。同时,加入了动画效果,使得进度条更加生动。开发环...

gitblog_06744的博客 979

Hermes接入IMA知识库全攻略:将知识库装进你的Hermes智能体

本文详细介绍了如何将IMA知识库功能接入Hermes Agent平台,实现一站式笔记管理和知识库操作。主要内容包括:获取IMA访问凭证、下载技能包、配置凭据(支持文件和环境变量两种方式)、验证配置有效性,以及实际应用演示(查询知识库列表、创建笔记并添加到知识库)。文章还提供了常见问题解决方案,如认证失败处理、版本更新等。通过该集成,用户可在Hermes中直接调用IMA的笔记创建、知识库管理等强大功能,提升工作效率。

小石头的专栏 641

Qt绘制电池进度条示例代码:优化界面交互的利器

Qt绘制电池进度条示例代码:优化界面交互的利器 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在软件开发中,用户界面的直观表达和友好交互至关重要。电池进度条作为展示电量状态的一种常见元素,在各类应用中都有广泛的应用。Qt绘制电池进度条示例代码项目,提供了一套基于Qt5.14.2的电池进度条绘制示例,旨在帮助开发者快速掌握Qt绘图技术,并应用于实际项目开发中。 项目技术...

gitblog_06755的博客 912

VTsystem背景检查函数Value Valid

Value Valid是个非常实用的函数,如何让它灵活的为我们所用,便是本文的内容。

欢迎来到eee的博客 795

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Qt绘制电池进度条(paintEvent)

做了一个电池的进度条,加了警示色和正常色的判断,还加了一些动画效果,分享一下,适合初学者,开发环境是Qt5.14.2+MSVC2017。想看源码的可以直接滑到最后有源码链接。

Q泥T挖的博客 2360

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Qt进阶-绘制一个电池

说明: MyBattery类继承自QWidget,在界面添加一个widget控件,提升为MyBattery类,将滑动条的valueChanged事件与sls_setValue()槽绑定。 borderWidth = 5; //边框宽度 borderRadius = 5; //边框倒角 currentValue = 0; //当前电量 alarmValue = 30; //电池电量警戒值 bgRadius = 5; //背景电量倒角 alarmColo

羽士的博客 763

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Qt绘制的电池电量显示小Demo:实时显示,自定义阈值,Qt控件的完美应用

Qt绘制的电池电量显示小Demo:实时显示,自定义阈值,Qt控件的完美应用 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在当今时代,软件界面的人性化设计至关重要,电池电量显示小Demo正是这样一个贴心的设计。Qt绘制的电池电量显示小Demo,一个基于Qt框架的GUI控件示例,能够动态展示电池电量的变化,为用户提供直观的电量信息。 项目技术分析 Qt绘制的电池电量显示...

gitblog_06715的博客 877

qt 获取android 剩余电量,Qt开源作品25-电池电量控件

一、前言现在这个时代,智能手机不要太流行,满大街都是,甚至连爷爷奶奶级别的人都会用智能手机,本次要写的控件就是智能手机中的电池电量表示控件,采用纯painter绘制,其实也可以采用贴图,我估计大部分手机上的都是采用贴图的形式,贴图有个好处就是程序员不用操心,drawimage即可,速度非常快。至于本控件没有任何技术难点,就是自动计算当前设置的电量,根据宽度的比例划分100个等分,每个等分占用多少个...

weixin_42108778的博客 702

QT自定义控件(电池)

做一个电池控件,需要一个拖动条和一个进度条。 不多说,直接上代码 .h文件 #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QProgressBar> #include <QSlider> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget();

家俊的博客 830
上一篇: qt mac窗体无边框后问题解决方案
下一篇: Mac/OSX 系统如何采集扬声器(代码实现 附源码)
很菜但努力
博客等级 码龄17年 113粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值