我是靠谱客的博主 年轻老师,这篇文章主要介绍画电池内部充电图标和显示百分比,现在分享给大家,希望可以做个参考。

//画电池内部充电图标

//画电池内部充电图标

void BatteryForm::drawCharge(QPainter *painter)
{

    painter->save();

    painter->setPen(QPen(Qt::red, 1, Qt::SolidLine));
    painter->setBrush(Qt::red);

    //定义6个点
    static const QPointF points[ 6 ] = {
        QPointF(batteryRect.width() * 60 / 100 + 13, batteryRect.height() * 15 / 100),//point1
        QPointF(batteryRect.width() * 40 / 100 + 13, batteryRect.height() * 55 / 100),//point2
        QPointF(batteryRect.width() * 50 / 100 + 13, batteryRect.height() * 55 / 100),//point3

        QPointF(batteryRect.width() * 40 / 100 + 13, batteryRect.height() * 90 / 100),//point4
        QPointF(batteryRect.width() * 60 / 100 + 13, batteryRect.height() * 45 / 100),//point5
        QPointF(batteryRect.width() * 50 / 100 + 13, batteryRect.height() * 45 / 100),//point6
    };
    painter->drawPolygon(points, 6);
    painter->restore();
}

//电池内部显示百分比

void BatteryForm::drawPercentText(QPainter *painter)
{
    painter->save();

    QFontMetrics textSize(this->font());
    int ipow = qRound(currentValue / (maxValue - minValue) * 100);
    if(ipow > 100)
    {
        ipow = 100;
    }
    else if(ipow < 0)
    {
        ipow = 0;
    }
    QString powStr = QString::number(ipow) + '%';
    //QRect textRect = textSize.boundingRect(powStr);  //得到字符串的rect

    painter->setFont(textFont);
    painter->setPen(textColor);
    /*painter->drawText(batteryRect.width() / 2 - textRect.width() / 2,
                      batteryRect.height() / 2 + textRect.height(),
                      powStr);*/
    painter->drawText(batteryRect, powStr, Qt::AlignLeft | Qt::AlignVCenter);
    painter->restore();
}

 

 

最后

以上就是年轻老师最近收集整理的关于画电池内部充电图标和显示百分比的全部内容,更多相关画电池内部充电图标和显示百分比内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部