update:显示进度条

This commit is contained in:
2025-06-12 22:44:20 +08:00
parent f7baf015c0
commit 50c916a8cc
3 changed files with 71 additions and 79 deletions

View File

@@ -1,35 +1,31 @@
#ifndef APPDELEGATE_H
#define APPDELEGATE_H
#pragma once
#include <QStyledItemDelegate>
#include <QPainter>
#include <QEvent>
#include <QMouseEvent>
// 前向声明 DownloadManager 类
class DownloadManager;
#include <QHash>
#include "downloadmanager.h"
class AppDelegate : public QStyledItemDelegate
{
struct DownloadInfo {
int progress = 0;
bool isDownloading = false;
};
class AppDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit AppDelegate(QObject *parent = nullptr);
// 重写方法
void setModel(QAbstractItemModel *model);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index) override;
signals:
void updateDisplay(); // 声明更新显示的信号
void updateDisplay(const QString &packageName);
private:
struct DownloadInfo {
int progress = 0;
bool isDownloading = false;
};
QHash<QString, DownloadInfo> m_downloads; // 使用包名作为键的下载状态
DownloadManager *m_downloadManager;
QHash<QString, DownloadInfo> m_downloads;
QAbstractItemModel *m_model = nullptr;
};
#endif // APPDELEGATE_H