#include <QPushButton>#include <QPainter>class CustomButton : public QPushButton { Q_OBJECTpublic: CustomButton(QWidget *parent = 0); ~CustomButton();public: QString FirstName,MiddleName,Lastname; QImage SimileIcon; bool IsBkColorEnabled; QColor Bkclor;protected: void paintEvent(QPaintEvent *);};
CustomButton::CustomButton(QWidget *parent) : QPushButton(parent){}CustomButton::~CustomButton(){}void CustomButton::paintEvent(QPaintEvent *paint){ QPushButton::paintEvent(paint); QPainter p(this); p.save(); p.setFont(QFont("Arial", 20)); p.restore();}
button1=new CustomButton; button1->setText(" Push");
QPushButton1::QPushButton1(QString &text) { setText(text); this->setAttribute(Qt::WA_Hover); this->installEventFilter(this); }bool QPushButton1::eventFilter(QObject * obj, QEvent * event){ if (obj == this) { QEvent::Type type = event->type(); if (type == QEvent::HoverLeave) { this->setCursor(Qt::ArrowCursor); } else if (type == QEvent::HoverEnter) { this->setCursor(Qt::PointingHandCursor); } } return QWidget::eventFilter(obj, event);}
void QPushButton::paintEvent ( QPaintEvent * event ){this->setFixedSize(80,30);QPainter painter(this);QLinearGradient myGradient(0,0,150,30);QPen myPen;myPen.setBrush(Qt::black);QRectF boundingRectangle(0,0,79,29);QPainterPath myPath;myPath.addEllipse(boundingRectangle);myGradient.setColorAt (0.0,Qt::white);painter.setPen(myPen);if (this->underMouse()==0){myGradient.setColorAt (1.0,Qt::yellow);}else if (this->underMouse()==1){myGradient.setColorAt (1.0,Qt::red);};painter.setBrush(myGradient);painter.drawPath(myPath);painter.setFont(QFont("Arial", 9));painter.drawText(rect(), Qt::AlignCenter, text());}