QPropertyAnimation Sliding Menu From Right Toolbar
-
Hi. I am trying to do up a sliding dialog widget, which it will slide out from the right docked toolbar upon clicking on the tool button. Upon clicking on the tool button again, it will slide in back to the right docked toolbar.
Previously, this is what I have done. Basically, I show() and hide() my dialog widget.
@void ToolBarPalettes::openPalette()
{
if(openPaletteButton->isChecked())
{
paletteDlg->show();
}
else
{
paletteDlg->hide();
}
}@I tried to do the following to allow it to animate (slide out) from the toolbar. However, when I click on my tool button, nothing happens. The dialog widget did not slide out.
@void ToolBarPalettes::openPalette()
{
if(openPaletteButton->isChecked())
{
QPropertyAnimation *animation = new QPropertyAnimation(paletteDlg, "geometry");
animation->setDuration(3000);
animation->setStartValue(QRect(-100, 50, paletteDlg->width(), paletteDlg->height()));
animation->setEndValue(QRect(50, 50, paletteDlg->width(), paletteDlg->height()));
animation->start();
}
else
{
QPropertyAnimation *animation = new QPropertyAnimation(paletteDlg, "geometry");
animation->setDuration(3000);
animation->setStartValue(QRect(50, 50, paletteDlg->width(), paletteDlg->height()));
animation->setEndValue(QRect(-100, 50, paletteDlg->width(), paletteDlg->height()));
animation->start();
}
}@Do I need to include the show() and hide() anywhere? Can anyone please help with this?
Thanks! -
Hi,
Are you sure that your dialog is already visible before you start animation ?
-
Yes. When I call paletteDlg->show() and paletteDlg->hide(), the dialog can be shown and hidden.
-
Yes indeed it can be, but my question is before you start the animation is paletteDlg already visible ?
Or can you add paletteDlg->show() before
@QPropertyAnimation *animation = new QPropertyAnimation(paletteDlg, "geometry");@
which is in
@
if(openPaletteButton->isChecked())
{}@
and try if it works -
Thanks p3c0! I included paletteDlg->show() before (or even after)
@animation->start();@
And both methods work well. I thought with specifying the geometry coordinates of QRect, I do not need to specify show() or hide().
-
Yes even after will work as start() doesn't wait for animation to be finished but some frames may be invisible till that time.