msbutton.h

#ifndef MSBUTTON_H
#define MSBUTTON_H

#include <QPushButton>

class MSButton : public QPushButton
{
public:
MSButton();
MSButton(QWidget *parent);


protected:
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
};

#endif // MSBUTTON_H

msbutton.cpp

#include "msbutton.h"

MSButton::MSButton()
{

}

MSButton::MSButton(QWidget *parent):
QPushButton(parent)
{


}


void MSButton::mousePressEvent(QMouseEvent *e){
QPushButton::mousePressEvent(e); //将事件操作权返回给父类
this->move(this->pos().x()+3,this->pos().y()+3);

}

void MSButton::mouseReleaseEvent(QMouseEvent *e) {
QPushButton::mouseReleaseEvent(e); //将事件操作权返回给父类
this->move(this->pos().x()-3,this->pos().y()-3);

}

QT 继承QPushButton实现点击效果_qt

QT 继承QPushButton实现点击效果_开发语言_02