DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dbuttonbox.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DBUTTONBOX_H
6#define DBUTTONBOX_H
7
8#include <dtkwidget_global.h>
9#include <DObject>
10#include <DStyle>
11#include <DDciIcon>
12
13#include <QAbstractButton>
14
15DWIDGET_BEGIN_NAMESPACE
16
17class DStyleOptionButtonBoxButton;
18class DButtonBoxButtonPrivate;
19class DButtonBoxButton : public QAbstractButton, public DCORE_NAMESPACE::DObject
20{
21 Q_OBJECT
22 D_DECLARE_PRIVATE(DButtonBoxButton)
23
24public:
25 explicit DButtonBoxButton(const QString &text, QWidget *parent = nullptr);
26 DButtonBoxButton(const QIcon& icon, const QString &text = QString(), QWidget *parent = nullptr);
27 DButtonBoxButton(QStyle::StandardPixmap iconType = static_cast<QStyle::StandardPixmap>(-1),
28 const QString &text = QString(), QWidget *parent = nullptr);
30 const QString &text = QString(), QWidget *parent = nullptr);
31 DButtonBoxButton(const DDciIcon &dciIcon, const QString &text = QString(), QWidget *parent = nullptr);
32
33 void setIcon(const QIcon &icon);
34 void setIcon(QStyle::StandardPixmap iconType);
35 void setIcon(DStyle::StandardPixmap iconType);
36
37 void setIcon(const DDciIcon &icon);
38 DDciIcon dciIcon() const;
39
40 QSize iconSize() const;
41 QSize sizeHint() const;
42 QSize minimumSizeHint() const override;
43
44private:
45 void initStyleOption(DStyleOptionButtonBoxButton *option) const;
46
47 void paintEvent(QPaintEvent *e) override;
48 void keyPressEvent(QKeyEvent *event) override;
49 bool event(QEvent *e) override;
50
51 friend class DButtonBox;
52};
53
55class DButtonBox : public QWidget, public DCORE_NAMESPACE::DObject
56{
57 Q_OBJECT
58 D_DECLARE_PRIVATE(DButtonBox)
59
60public:
61 explicit DButtonBox(QWidget *parent = nullptr);
62
63 Qt::Orientation orientation() const;
64 void setOrientation(Qt::Orientation orientation);
65
66 void setButtonList(const QList<DButtonBoxButton*> &list, bool checkable);
67 QList<QAbstractButton*> buttonList() const;
68
69 QAbstractButton * checkedButton() const;
70 // no setter on purpose!
71
72 QAbstractButton *button(int id) const;
73 void setId(QAbstractButton *button, int id);
74 int id(QAbstractButton *button) const;
75 int checkedId() const;
76
77Q_SIGNALS:
78 void buttonClicked(QAbstractButton *);
79 void buttonPressed(QAbstractButton *);
80 void buttonReleased(QAbstractButton *);
81 void buttonToggled(QAbstractButton *, bool);
82
83protected:
84 bool eventFilter(QObject *o, QEvent *e) override;
85
86private:
87 void paintEvent(QPaintEvent *e) override;
88
89 friend class DButtonBoxButton;
90};
91
92DWIDGET_END_NAMESPACE
93
94#endif // DBUTTONBOX_H
DButtonBoxButton类 提供了在 DButtonBox类 中使用的可修改样式的图标按钮.
Definition dbuttonbox.h:20
Definition dbuttonbox_p.h:21
DButtonBox 类似于 QButtonGroup 类.
Definition dbuttonbox.h:56
Definition dstyleoption.h:77
StandardPixmap
Definition dstyle.h:188