qt备忘录(让图标变大,变小)

来源:互联网 发布:java过滤回车换行 编辑:程序博客网 时间:2024/04/28 06:55

要写成下面的形式才能确保鼠标进入后实现图标的变大或变小:

在.h中:

#ifndef HHHHH_H

#define HHHHH_H
#include <QToolButton>
class hhhhh : public QToolButton
{
    Q_OBJECT
public:
    explicit hhhhh(QWidget *parent = 0);
signals:
public slots:
protected:
    void leaveEvent(QEvent *);
    void enterEvent(QEvent *);
};
#endif // HHHHH_H
 
在.c中:
void hhhhh::leaveEvent(QEvent *)
{
    this->setGeometry(this->x(),this->y()
                      ,this->width()-10,this->height()-10);
}
void hhhhh::enterEvent(QEvent *)
{
    this->setGeometry(this->x(),this->y()
                      ,this->width()+10,this->height()+10);
}