diff --git a/docs/images/DIconButton_example.png b/docs/images/DIconButton_example.png new file mode 100644 index 000000000..413c3c153 Binary files /dev/null and b/docs/images/DIconButton_example.png differ diff --git a/docs/widgets/diconbutton.zh_CN.dox b/docs/widgets/diconbutton.zh_CN.dox index c83e04800..70b53da4b 100644 --- a/docs/widgets/diconbutton.zh_CN.dox +++ b/docs/widgets/diconbutton.zh_CN.dox @@ -2,11 +2,83 @@ @~chinese @file diconbutton.h @ingroup button -@class -@brief -@details -TODO: 添加类简介、示例代码、示例截图和函数使用说明等 +@class Dtk::Widget::DIconButton +@brief 按钮的图标 +@details 定制化的按钮图标,可以根据传入的图标参数具体调整 +### 示例代码 +#### main.cpp +```cpp +#include +#include +#include +#include +DWIDGET_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + DApplication app(argc, argv); + DMainWindow window; + window.setMinimumSize(QSize(600, 200)); + + QWidget *centralWidget = new QWidget(&window); + QVBoxLayout *layout = new QVBoxLayout(centralWidget); + + DIconButton *button1 = new DIconButton(QStyle::SP_DirIcon); + button1->setNewNotification(true); // 显示小红点 + button1->setIconSize(QSize(32, 32)); // 设置图标尺寸为 32x32 + layout->addWidget(button1); + + DIconButton *button2 = new DIconButton(); + button2->setIcon(QIcon("image.jpg")); // 使用本地的图片作为icon + button2->setIconSize(QSize(48, 48)); // 设置图标尺寸为 48x48 + layout->addWidget(button2); + + DIconButton *button3 = new DIconButton(QStyle::SP_ComputerIcon); + button3->setIconSize(QSize(64, 64)); // 设置图标尺寸为 64x64 + layout->addWidget(button3); + + window.setCentralWidget(centralWidget); + window.show(); + + return app.exec(); +} +``` +### demo运行图片 +@image html DIconButton_example.png + +@fn DIconButton::DIconButton(QWidget *parent) +@brief 实现一个方便定义图标的button +@param[in] parent + +@fn void DIconButton::setIcon(const QIcon &icon) +@brief 设置button的图标 +@param[in] icon button的图标 + +@fn void DIconButton::setIcon(QStyle::StandardPixmap iconType) +@brief 设置button图标的类型,传入QT预定义枚举值 +@param[in] iconType icon类型 + +@fn void DIconButton::setIcon(DStyle::StandardPixmap iconType) +@brief 设置button图标的类型,传入DTK预定义枚举值 +@param[in] iconType icon类型 + +@fn QSize DIconButton::iconSize() const +@brief icon的尺寸 +@return 返回icon的尺寸 + +@fn bool DIconButton::isFlat() const +@brief button图标有无边框 +@return true无边框 false有边框 + +@fn void DIconButton::setFlat(bool flat) +@brief 设置是否保留边框 +@param[in] flat true无边框 false有边框 + +@fn void DIconButton::setNewNotification(const bool set_new) +@brief 设置是否显示小红点 +@param[in] set_new true有红点 false无红点 */ + diff --git a/src/widgets/diconbutton.cpp b/src/widgets/diconbutton.cpp index 2b471d31c..eb4949389 100644 --- a/src/widgets/diconbutton.cpp +++ b/src/widgets/diconbutton.cpp @@ -19,8 +19,16 @@ DIconButtonPrivate::DIconButtonPrivate(DIconButton *qq) } /*! - \brief DIconButton::DIconButton 实现一个方便定义图标的button - \a parent +@~english + @class Dtk::Widget::DIconButton + @brief the button icon + @details Customized button icons that can be adjusted according to the input icon parameters. + */ + +/*! +@~english + @brief DIconButton::DIconButton implement a button easy to define icons + @param[in] parent */ DIconButton::DIconButton(QWidget *parent) : DIconButton(*new DIconButtonPrivate(this), parent) @@ -53,8 +61,9 @@ DIconButton::~DIconButton() } /*! - \brief DIconButton::setIcon 设置button的图标 - \a icon button的图标 +@~english + @brief DIconButton::setIcon set the button icon + @param[in] icon the button icon */ void DIconButton::setIcon(const QIcon &icon) { @@ -65,8 +74,9 @@ void DIconButton::setIcon(const QIcon &icon) } /*! - \brief DIconButton::setIcon 设置button图标的类型,传入QT预定义枚举值 - \a iconType icon类型 +@~english + @brief DIconButton::setIcon Set the type of the Button icon and pass the predefined enumeration value of QT. + @param[in] iconType type of icon */ void DIconButton::setIcon(QStyle::StandardPixmap iconType) { @@ -77,8 +87,9 @@ void DIconButton::setIcon(QStyle::StandardPixmap iconType) } /*! - \brief DIconButton::setIcon 设置button图标的类型,传入DTK预定义枚举值 - \a iconType icon类型 +@~english + @brief DIconButton::setIcon Set the type of the Button icon and pass the predefined enumeration value of DTK. + @param[in] iconType type of icon */ void DIconButton::setIcon(DStyle::StandardPixmap iconType) { @@ -131,8 +142,9 @@ QSize DIconButton::minimumSizeHint() const } /*! - \brief DIconButton::iconSize - \return 返回ICON的尺寸 +@~english + @brief DIconButton::iconSize + @return size of icon */ QSize DIconButton::iconSize() const { @@ -153,8 +165,9 @@ QSize DIconButton::iconSize() const } /*! - \brief DIconButton::isFlat - \return true无边框 false有边框 +@~english + @brief DIconButton::isFlat + @return "true":no frame "false":frame */ bool DIconButton::isFlat() const { @@ -182,8 +195,9 @@ bool DIconButton::enabledCircle() const } /*! - \brief DIconButton::setFlat 设置是否保留边框 - \a flat true无边框 false有边框 +@~english + @brief DIconButton::setFlat set whether to keep the frame + @param[in] flat "true":no frame "false":frame */ void DIconButton::setFlat(bool flat) { @@ -270,8 +284,9 @@ void DIconButton::keyPressEvent(QKeyEvent *event) } /*! - \brief DIconButton::setNewNotification 设置是否显示小红点 - \a set_new true有红点 false无红点 +@~english + @brief DIconButton::setNewNotification set whether to show small red dots + @param[in] set_new "true":small red dots "false":no small red dots */ void DIconButton::setNewNotification(const bool set_new) { @@ -302,7 +317,7 @@ bool DIconButton::event(QEvent *e) } } } else if (e->type() == QEvent::ShowToParent) { - // 默认调整大小,否则可能会导致按钮显示后为 QWidget 的默认大小 + // Resize by default, otherwise it may cause the button to display at the default size of QWidget. resize(sizeHint()); }