qt_demoe/control/imageswitch/imageswitch.h

64 lines
1.5 KiB
C
Raw Permalink Normal View History

2020-02-11 08:22:51 +00:00
#ifndef IMAGESWITCH_H
#define IMAGESWITCH_H
/**
* :feiyangqingyun(QQ:517216493) 2016-11-25
2021-09-13 08:12:35 +00:00
* 1.
* 2.
2020-02-11 08:22:51 +00:00
*/
#include <QWidget>
#ifdef quc
2020-12-24 10:00:09 +00:00
class Q_DECL_EXPORT ImageSwitch : public QWidget
2020-02-11 08:22:51 +00:00
#else
class ImageSwitch : public QWidget
#endif
{
Q_OBJECT
Q_ENUMS(ButtonStyle)
Q_PROPERTY(bool isChecked READ getChecked WRITE setChecked)
Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle)
public:
enum ButtonStyle {
ButtonStyle_1 = 0, //开关样式1
ButtonStyle_2 = 1, //开关样式2
ButtonStyle_3 = 2 //开关样式3
};
explicit ImageSwitch(QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent *);
void paintEvent(QPaintEvent *event);
private:
2023-09-08 05:51:39 +00:00
bool isChecked; //是否选中
ButtonStyle buttonStyle; //按钮样式
2020-02-11 08:22:51 +00:00
2023-09-08 05:51:39 +00:00
QString imgOffFile; //关闭图片
QString imgOnFile; //开启图片
QString imgFile; //当前图片
2020-02-11 08:22:51 +00:00
public:
2023-09-08 05:51:39 +00:00
//默认尺寸和最小尺寸
QSize sizeHint() const;
QSize minimumSizeHint() const;
2022-04-28 00:35:52 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置是否选中
bool getChecked() const;
2020-02-11 08:22:51 +00:00
void setChecked(bool isChecked);
2023-09-08 05:51:39 +00:00
//获取和设置按钮样式
ButtonStyle getButtonStyle() const;
2020-02-11 08:22:51 +00:00
void setButtonStyle(const ImageSwitch::ButtonStyle &buttonStyle);
2022-04-28 00:35:52 +00:00
Q_SIGNALS:
void checkedChanged(bool checked);
2020-02-11 08:22:51 +00:00
};
#endif // IMAGESWITCH_H