hyperk-021
2025-06-05 8c679ef19e9d5c33947cdf1cc1e5550e3d442308
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
 
#include <QStyledItemDelegate>
#include <QAbstractItemView>
#include <QEvent>
#include <QMouseEvent>
#include <QApplication>
#include <QObject>
#include <QPushButton>
#include <QPainter>
 
namespace Ripples {
 
// 自定义按钮委托类
class CustomButtonDelegate : public QStyledItemDelegate {
    Q_OBJECT
public:
    mutable QPersistentModelIndex pressedIndex;  // 保持按下状态
    mutable QPersistentModelIndex hoveredIndex;  // 鼠标悬停状态
 
    explicit CustomButtonDelegate(const QStringList& m_iconPathList, QObject *parent = nullptr);
 
    ~CustomButtonDelegate(){
        qDebug() << "已删除";
    }
 
 
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
 
    bool editorEvent(QEvent *event, QAbstractItemModel *model,
                     const QStyleOptionViewItem &option, const QModelIndex &index) override;
 
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
 
 
private:
    void requestUpdate(const QStyleOptionViewItem &option, const QModelIndex &index) const;
 
private:
    QStringList m_iconPathList;
 
signals:
    void iconClicked(const QModelIndex &index);
 
};
 
 
} // namespace Ripples