1 Star 0 Fork 6

pandygui/HTYFileManager

forked from morixinguan/HTYFileManager 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
form_disk.cpp 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
#include "form_disk.h"
#include "ui_form_disk.h"
#include <QDebug>
#include <QIcon>
Form_disk::Form_disk(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form_disk)
{
ui->setupUi(this);
ui->label_icon->setPixmap(QIcon::fromTheme("drive-harddisk").pixmap(70,70));
}
Form_disk::~Form_disk()
{
delete ui;
}
void Form_disk::init()
{
QFontMetrics fontMetrics(ui->label->font());
QString name_elide = fontMetrics.elidedText(name, Qt::ElideRight, ui->label->width());
ui->label->setText(name_elide);
ui->label->setToolTip(name);
qint64 bytesUsed = bytesTotal - bytesFree;
ui->label_bytes->setText(BS(bytesUsed) + " / " + BS(bytesTotal));
ui->progressBar->setRange(0, 100);
int value = 100 * bytesUsed / bytesTotal;
//qDebug() << value;
ui->progressBar->setValue(value);
QString style;
if(value < 60){
style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }"
"QProgressBar::chunk { background-color: dodgerblue; }";
}else if(value < 80){
style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }"
"QProgressBar::chunk { background-color: orange; }";
}else{
style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }"
"QProgressBar::chunk { background-color: red; }";
}
ui->progressBar->setStyleSheet(style);
}
QString Form_disk::BS(qint64 b)
{
QString s = "";
if (b > 999999999) {
s = QString::number(b/(1024*1024*1024)) + " GB";
} else {
if (b > 999999){
s = QString::number(b/(1024*1024)) + " MB";
} else {
if (b > 999) {
s = QString::number(b/1024) + " KB";
} else {
s = QString::number(b)+" B";
}
}
}
return s;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/pandygui/HTYFileManager.git
git@gitee.com:pandygui/HTYFileManager.git
pandygui
HTYFileManager
HTYFileManager
master

搜索帮助