Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgitpr committed Oct 20, 2024
1 parent a2ba444 commit b1c2a76
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/apps/MinLabel/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <QLineEdit>
#include <QMenuBar>
#include <QMessageBox>
#include <QTreeWidget>
#include <QMimeData>
#include <QStatusBar>
#include <QStyledItemDelegate>
#include <QTreeWidget>
#include <utility>

#include "QMSystem.h"
Expand All @@ -34,11 +34,26 @@ class CustomDelegate final : public QStyledItemDelegate {
const QFileInfo fileInfo(model->filePath(index));
const QString jsonFilePath = fileInfo.absolutePath() + "/" + fileInfo.completeBaseName() + ".json";

// 默认设置为黑色
QStyleOptionViewItem modifiedOption(option);
if (QFile::exists(jsonFilePath) && fileInfo.isFile() && QFileInfo(jsonFilePath).size() > 0) {
modifiedOption.palette.setColor(QPalette::Text, Qt::gray);
} else {
modifiedOption.palette.setColor(QPalette::Text, Qt::black);
modifiedOption.palette.setColor(QPalette::Text, Qt::black);

// 如果 JSON 文件存在且可读
if (QFile::exists(jsonFilePath) && fileInfo.isFile()) {
QFile jsonFile(jsonFilePath);
if (jsonFile.open(QIODevice::ReadOnly)) {
const QByteArray jsonData = jsonFile.readAll();
jsonFile.close();

const QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonData));
if (jsonDoc.isObject()) {
const QJsonObject jsonObj = jsonDoc.object();
// 判断 isCheck 是否存在且为 true
if (jsonObj.value("isCheck").toBool(false)) {
modifiedOption.palette.setColor(QPalette::Text, Qt::gray);
}
}
}
}

QStyledItemDelegate::paint(painter, modifiedOption, index);
Expand Down

0 comments on commit b1c2a76

Please sign in to comment.