// This is mainWidget, where in I'll show the menu
#include "cmainwidget.h"
CMainWidget
::CMainWidget(QWidget *parent
){
this->setMouseTracking(true);
this->setFixedSize(650, 400);
menuWidget = new CMenuWidget(this);
menuWidget->hide();
mAnimation = new QPropertyAnimation(menuWidget, "geometry");
mAnimation->setDuration(250); // Increasing this isn't helping in smooth transition, instead it's affecting hide when the mouse is > 80 in "else if" in mouseMoveEvent
mAnimation->setEasingCurve(QEasingCurve::InOutElastic);
}
CMainWidget::~CMainWidget()
{
delete mAnimation;
delete menuWidget;
}
{
if(mmEvent->pos().x() <= 80)
{
qDebug("Mouse X-Position - %d", mmEvent->pos().x());
mAnimation
->setStartValue
(QRect(0,
40,
0,
40));
mAnimation
->setEndValue
(QRect(0,
40, menuWidget
->sizeHint
().
width(),
40));
disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
mAnimation->start();
menuWidget->show();
}
else if(mmEvent->pos().x() > 80)
{
qDebug("Mouse X-Position - %d", mmEvent->pos().x());
mAnimation
->setEndValue
(QRect(0,
40,
0,
40));
mAnimation
->setStartValue
(QRect(0,
40, menuWidget
->sizeHint
().
width(),
40));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
mAnimation->start();
}
}
void CMainWidget::hideMenuWid()
{
menuWidget->hide();
}
// This is mainWidget, where in I'll show the menu
#include "cmainwidget.h"
CMainWidget::CMainWidget(QWidget *parent)
: QWidget(parent)
{
this->setMouseTracking(true);
this->setFixedSize(650, 400);
menuWidget = new CMenuWidget(this);
menuWidget->hide();
mAnimation = new QPropertyAnimation(menuWidget, "geometry");
mAnimation->setDuration(250); // Increasing this isn't helping in smooth transition, instead it's affecting hide when the mouse is > 80 in "else if" in mouseMoveEvent
mAnimation->setEasingCurve(QEasingCurve::InOutElastic);
}
CMainWidget::~CMainWidget()
{
delete mAnimation;
delete menuWidget;
}
void CMainWidget::mouseMoveEvent(QMouseEvent *mmEvent)
{
if(mmEvent->pos().x() <= 80)
{
qDebug("Mouse X-Position - %d", mmEvent->pos().x());
mAnimation->setStartValue(QRect(0, 40, 0, 40));
mAnimation->setEndValue(QRect(0, 40, menuWidget->sizeHint().width(), 40));
disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
mAnimation->start();
menuWidget->show();
}
else if(mmEvent->pos().x() > 80)
{
qDebug("Mouse X-Position - %d", mmEvent->pos().x());
mAnimation->setEndValue(QRect(0, 40, 0, 40));
mAnimation->setStartValue(QRect(0, 40, menuWidget->sizeHint().width(), 40));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
mAnimation->start();
}
}
void CMainWidget::hideMenuWid()
{
menuWidget->hide();
}
To copy to clipboard, switch view to plain text mode
Bookmarks