mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
add qqtsvgcheckbox
This commit is contained in:
parent
1f7b5eda90
commit
6d049c0a56
@ -14,10 +14,12 @@
|
||||
#-------------------------------------------------
|
||||
SOURCES += \
|
||||
$$PWD/svgwidgets/qqtsvgwidget.cpp \
|
||||
$$PWD/svgwidgets/qqtsvgpushbutton.cpp
|
||||
$$PWD/svgwidgets/qqtsvgpushbutton.cpp \
|
||||
$$PWD/svgwidgets/qqtsvgcheckbox.cpp
|
||||
HEADERS += \
|
||||
$$PWD/svgwidgets/qqtsvgwidget.h \
|
||||
$$PWD/svgwidgets/qqtsvgpushbutton.h
|
||||
$$PWD/svgwidgets/qqtsvgpushbutton.h \
|
||||
$$PWD/svgwidgets/qqtsvgcheckbox.h
|
||||
|
||||
#root dir
|
||||
HEADERS += $$PWD/qqt.h \
|
||||
|
@ -4,3 +4,27 @@ QQtSvgCheckBox::QQtSvgCheckBox(QWidget* parent) : QQtCheckBox(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QQtSvgCheckBox::renderToVariable()
|
||||
{
|
||||
TBtnIconTable& pic = iconTable();
|
||||
|
||||
for (int i = 0; i < BTN_MAX; i++)
|
||||
r[i].load(pic[i]);
|
||||
}
|
||||
|
||||
|
||||
void QQtSvgCheckBox::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QStylePainter p(this);
|
||||
int bs = isChecked() ? BTN_PRESS : BTN_NORMAL;
|
||||
if (r[bs].isValid())
|
||||
r[bs].render(&p);
|
||||
|
||||
bool enabled = isEnabled();
|
||||
QStyleOptionButton opt;
|
||||
initStyleOption(&opt);
|
||||
p.drawItemText(rect(), Qt::AlignBottom, opt.palette, enabled, text());
|
||||
}
|
||||
|
@ -9,9 +9,20 @@ class QQtSvgCheckBox : public QQtCheckBox
|
||||
public:
|
||||
explicit QQtSvgCheckBox(QWidget* parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief renderToVariable
|
||||
* call this function after iconTable() set.
|
||||
*/
|
||||
void renderToVariable();
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
private:
|
||||
QSvgRenderer r[BTN_MAX];
|
||||
};
|
||||
|
||||
#endif // QQTSVGCHECKBOX_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "qqtsvgpushbutton.h"
|
||||
#include <QString>
|
||||
|
||||
QQtSvgPushButton::QQtSvgPushButton(QWidget* parent) : QQtPushButton(parent)
|
||||
{
|
||||
@ -22,7 +21,8 @@ void QQtSvgPushButton::paintEvent(QPaintEvent* event)
|
||||
|
||||
QStylePainter p(this);
|
||||
EBtnStatus bs = btnStatus();
|
||||
r[bs].render(&p);
|
||||
if (r[bs].isValid())
|
||||
r[bs].render(&p);
|
||||
|
||||
bool enabled = isEnabled();
|
||||
QStyleOptionButton opt;
|
||||
|
@ -11,12 +11,18 @@ QQtCheckBox::~QQtCheckBox()
|
||||
{
|
||||
}
|
||||
|
||||
void QQtCheckBox::pixMap(QImage& icon, QImage& iconSel)
|
||||
void QQtCheckBox::pixMap(QImage& icon, QImage& iconSel) const
|
||||
{
|
||||
icon = QImage(this->m_icon[BTN_NORMAL]);
|
||||
iconSel = QImage(this->m_icon[BTN_PRESS]);
|
||||
}
|
||||
|
||||
void QQtCheckBox::pixMap(QString& icon, QString& iconSel) const
|
||||
{
|
||||
icon = m_icon[BTN_NORMAL];
|
||||
iconSel = m_icon[BTN_PRESS];
|
||||
}
|
||||
|
||||
void QQtCheckBox::setPixmap(const QString& icon, const QString& iconSel)
|
||||
{
|
||||
this->m_icon[BTN_NORMAL] = icon;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "qqtcore.h"
|
||||
#include "qqtwidgets.h"
|
||||
#include "qqt-local.h"
|
||||
#include <QSvgRenderer>
|
||||
#include <qqtwidgets.h>
|
||||
|
||||
/**
|
||||
* @brief The QQtCheckBox class
|
||||
@ -17,15 +19,19 @@ class QQTSHARED_EXPORT QQtCheckBox : public QCheckBox
|
||||
public:
|
||||
explicit QQtCheckBox(QWidget* parent = 0);
|
||||
virtual ~QQtCheckBox();
|
||||
void pixMap(QImage& m_icon, QImage& m_iconSel);
|
||||
void setPixmap(const QString& m_icon = QString(), const QString& m_iconSel = QString());
|
||||
|
||||
inline TBtnIconTable& iconTable() { return m_icon; }
|
||||
void pixMap(QImage& icon, QImage& iconSel) const;
|
||||
void pixMap(QString& icon, QString& iconSel) const;
|
||||
void setPixmap(const QString& icon = QString(),
|
||||
const QString& iconSel = QString());
|
||||
|
||||
private:
|
||||
TBtnIconTable m_icon;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
|
||||
// QAbstractButton interface
|
||||
protected:
|
||||
|
@ -12,7 +12,7 @@ class QQTSHARED_EXPORT QQtPushButton : public QPushButton
|
||||
|
||||
public:
|
||||
explicit QQtPushButton(QWidget* parent = 0);
|
||||
~QQtPushButton();
|
||||
virtual ~QQtPushButton();
|
||||
|
||||
/*
|
||||
* QQtPushButton [] = 不能正常运算 所以采用这种形式。
|
||||
@ -27,15 +27,15 @@ private:
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseReleaseEvent(QMouseEvent*);
|
||||
void enterEvent(QEvent*);
|
||||
void leaveEvent(QEvent*);
|
||||
void changeEvent(QEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent*) override;
|
||||
virtual void enterEvent(QEvent*) override;
|
||||
virtual void leaveEvent(QEvent*) override;
|
||||
virtual void changeEvent(QEvent* e) override;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user