Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
ebutton.cpp 1.58 KB
Copy Edit Web IDE Raw Blame History
unix_chen authored 2018-03-26 07:59 . init
#include "ebutton.h"
#include <QPainter>
EButton::EButton(QWidget *parent) : QPushButton(parent)
{
setDown(false);
setFocusPolicy(Qt::NoFocus);
setFlat(true);
}
EButton::~EButton()
{
}
void EButton::SetTexts(const char *text)
{
m_text = text;
}
void EButton::SetTexts(const QString &text)
{
m_text = text;
}
void EButton::SetButtonIcons(const QIcon &normal, const QIcon &focus, const QIcon &pressed)
{
m_normalIcon = normal;
m_focusIcon = focus;
m_pressedIcon = pressed;
setIcon(m_normalIcon);
}
void EButton::SetButtonIcons(const char *path)
{
QString p = ":/res/button/";
p += path;
m_normalIcon = QIcon(p + "/normal.png");
m_focusIcon = QIcon(p + "/focus.png");
m_pressedIcon = QIcon(p + "/pressed.png");
resize(78, 78);
setIcon(m_normalIcon);
setIconSize(QSize(78, 78));
}
void EButton::enterEvent(QEvent *event)
{
if( isEnabled() && !m_focusIcon.isNull())
setIcon(m_focusIcon);
}
void EButton::leaveEvent(QEvent *event)
{
if( isEnabled() )
setIcon(m_normalIcon);
}
void EButton::mousePressEvent(QMouseEvent *event)
{
if( isEnabled() && !m_pressedIcon.isNull() )
setIcon(m_pressedIcon);
QPushButton::mousePressEvent(event);
}
void EButton::mouseReleaseEvent(QMouseEvent *event)
{
if( isEnabled() && m_focusIcon.isNull() )
setIcon(m_focusIcon);
QPushButton::mouseReleaseEvent(event);
}
void EButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
QPainter lPainter(this);
if (m_text != "")
lPainter.drawText(rect(),Qt::AlignCenter, m_text);
}

Comment ( 0 )

Sign in for post a comment