//cbackbtnanime.h
#ifndef CBACKBTNANIME_H
#define CBACKBTNANIME_H
#include <QtGui>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QStyleOption>
class CBackBtnAnime
: public QWidget{
Q_OBJECT
private:
QPropertyAnimation * mAnimation;
public:
explicit CBackBtnAnime
(QWidget *parent
= 0);
protected:
{
Q_UNUSED(pe);
o.initFrom(this);
style
()->drawPrimitive
(QStyle::PE_Widget,
&o,
&p,
this);
}
{
if((parent
() == object
) & (event
->type
() == QEvent::MouseMove)) {
QMouseEvent * mouseEvent
= static_cast<QMouseEvent
*>
(event
);
if((mouseEvent->pos().x() < 50) && (mouseEvent->pos().y() < 30))
{
if(isHidden() && (mAnimation->state() != mAnimation->Running))
{
mAnimation
->setStartValue
(QRect(-2,
1,
0,
28));
mAnimation
->setEndValue
(QRect(0,
1,
50,
28));
disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
show();
}
}
else if(mAnimation->state() != mAnimation->Running)
{
if(!isHidden())
{
mAnimation
->setEndValue
(QRect(-2,
1,
0,
28));
mAnimation
->setStartValue
(QRect(0,
1,
50,
28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}
}
if((event
->type
() == QEvent::Leave) && (mAnimation
->state
() != mAnimation
->Running
)) {
qDebug("Inside QEvent::Leave");
if(!isHidden())
{
mAnimation
->setEndValue
(QRect(-2,
2,
0,
28));
mAnimation
->setStartValue
(QRect(0,
2,
50,
28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}
return QWidget::eventFilter(object, event
);
}
signals:
void backBtnClicked();
public slots:
};
#endif // CBACKBTNANIME_H
//cbackbtnanime.h
#ifndef CBACKBTNANIME_H
#define CBACKBTNANIME_H
#include <QtGui>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QStyleOption>
class CBackBtnAnime : public QWidget
{
Q_OBJECT
private:
QPushButton *backBtn;
QHBoxLayout *hLyt;
QPropertyAnimation * mAnimation;
public:
explicit CBackBtnAnime(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *pe)
{
Q_UNUSED(pe);
QStyleOption o;
o.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
}
bool eventFilter(QObject * object, QEvent * event)
{
if((parent() == object) & (event->type() == QEvent::MouseMove))
{
QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
if((mouseEvent->pos().x() < 50) && (mouseEvent->pos().y() < 30))
{
if(isHidden() && (mAnimation->state() != mAnimation->Running))
{
mAnimation->setStartValue(QRect(-2, 1, 0, 28));
mAnimation->setEndValue(QRect(0, 1, 50, 28));
disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
show();
}
}
else if(mAnimation->state() != mAnimation->Running)
{
if(!isHidden())
{
mAnimation->setEndValue(QRect(-2, 1, 0, 28));
mAnimation->setStartValue(QRect(0, 1, 50, 28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}
}
if((event->type() == QEvent::Leave) && (mAnimation->state() != mAnimation->Running))
{
qDebug("Inside QEvent::Leave");
if(!isHidden())
{
mAnimation->setEndValue(QRect(-2, 2, 0, 28));
mAnimation->setStartValue(QRect(0, 2, 50, 28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}
return QWidget::eventFilter(object, event);
}
signals:
void backBtnClicked();
public slots:
};
#endif // CBACKBTNANIME_H
To copy to clipboard, switch view to plain text mode
//cbackbtmanime.cpp
#include "cbackbtnanime.h"
CBackBtnAnime
::CBackBtnAnime(QWidget *parent
) :{
this->setMouseTracking(true);
this->installEventFilter(this);
this->setStyleSheet("background-color: #454545;");
parent->installEventFilter(this);
mAnimation = new QPropertyAnimation(this, "geometry");
mAnimation->setDuration(250);
backBtn->setFixedSize(50, 28);
backBtn
->setIcon
(QIcon(":/imgs/backToHome.png"));
backBtn
->setIconSize
(QSize(50,
28));
backBtn->setStyleSheet("QPushButton { background: transparent; border: 0px; border-radius: 20px; padding: 0px;}"
"QPushButton:hover {background: transparent; border: 1px solid #4cd3f5;}"
"QPushButton:pressed {background: transparent; border: 2px solid #4cd3f5;}"
"QToolTip {background: white; color: black; }");
connect(backBtn, SIGNAL(clicked()), this, SIGNAL(backBtnClicked()));
hLyt->setContentsMargins(0, 0, 0, 0);
this->setLayout(hLyt);
hLyt->addWidget(backBtn);
}
//cbackbtmanime.cpp
#include "cbackbtnanime.h"
CBackBtnAnime::CBackBtnAnime(QWidget *parent) :
QWidget(parent)
{
this->setMouseTracking(true);
this->installEventFilter(this);
this->setStyleSheet("background-color: #454545;");
parent->installEventFilter(this);
mAnimation = new QPropertyAnimation(this, "geometry");
mAnimation->setDuration(250);
backBtn = new QPushButton(this);
backBtn->setFixedSize(50, 28);
backBtn->setIcon(QIcon(":/imgs/backToHome.png"));
backBtn->setIconSize(QSize(50, 28));
backBtn->setStyleSheet("QPushButton { background: transparent; border: 0px; border-radius: 20px; padding: 0px;}"
"QPushButton:hover {background: transparent; border: 1px solid #4cd3f5;}"
"QPushButton:pressed {background: transparent; border: 2px solid #4cd3f5;}"
"QToolTip {background: white; color: black; }");
connect(backBtn, SIGNAL(clicked()), this, SIGNAL(backBtnClicked()));
hLyt = new QHBoxLayout();
hLyt->setContentsMargins(0, 0, 0, 0);
this->setLayout(hLyt);
hLyt->addWidget(backBtn);
}
To copy to clipboard, switch view to plain text mode
Bookmarks