MPushButton::MPushButton(const QString& iconPath, const QString& text, QWidget* parent)
: QPushButton(parent)
{
m_text = text;
m_icon = QPixmap(iconPath);
setFixedHeight(m_icon.size().height() + 15);
setMinimumWidth(m_icon.size().width());
m_drawedIconRect.setX((rect().x() - m_icon.rect().x()) / 2);
m_drawedIconRect.setY(rect().y());
m_drawedIconRect.setWidth(m_icon.rect().width());
m_drawedIconRect.setHeight(m_icon.rect().height());
}
void MPushButton::paintEvent(QPaintEvent* e)
{
QPainter painter(this);
painter.drawPixmap(m_drawedIconRect, m_icon);
painter.drawText(e->rect(), Qt::AlignHCenter | Qt::AlignBottom, m_text);
: QPushButton(parent)
{
m_text = text;
m_icon = QPixmap(iconPath);
setFixedHeight(m_icon.size().height() + 15);
setMinimumWidth(m_icon.size().width());
m_drawedIconRect.setX((rect().x() - m_icon.rect().x()) / 2);
m_drawedIconRect.setY(rect().y());
m_drawedIconRect.setWidth(m_icon.rect().width());
m_drawedIconRect.setHeight(m_icon.rect().height());
}
void MPushButton::paintEvent(QPaintEvent* e)
{
QPainter painter(this);
painter.drawPixmap(m_drawedIconRect, m_icon);
painter.drawText(e->rect(), Qt::AlignHCenter | Qt::AlignBottom, m_text);
}