0

I'm new to QT development (really new to it) and I wanted to create an app that displays a textbox and a button in the middle of the form, and when the user clicks on the button, the textbox and the button will slide up and a different control will be displayed below.

The textbox and the button will create kind of a toolbar and a content area will be revealed after the animation.

Here is a mockup of what I need: https://www.fluidui.com/editor/live/preview/p_bPVFbiowoKiedzMhbQKWHdOzuDaxORFg.1408042108162

And here is how the designer is:

QtCreator

How can I create a slide animation and display other widgets when the animation ends?

juliano.net
  • 7,982
  • 13
  • 70
  • 164

1 Answers1

1

( don't have the time to make it perfect code but you'll get the idea )

you could do something like this.

put this in your constructor:

    yPos = ui->whatever->y() + 1;

    tmr = new QTimer( );
    connect( tmr , SIGNAL( timeout( ) ) , this , SLOT( update( ) ) );
    tmr->setInterval( 2.5 );
    tmr->start();

    // End

this as a function or method:

void MainWindow::update()
{
    if( yPos < MainWindow::size().height() )
    {
        ui->whatever->move( ui->whatever->x() , yPos );
        ++yPos;
    }
    else
    {
        QMessageBox::about( 0 , "Out" , "I'm outta here!" );
        ui->whatever->hide();
        tmr->stop();
    }
}

This will get it moving down.

and like this it'll move up:

constructor:

    yPos = ui->whatever->y() - 1;
    hidingPoint = 0 - yPos - ui->whatever->size().height() + 1;

    tmr = new QTimer( );
    connect( tmr , SIGNAL( timeout( ) ) , this , SLOT( update( ) ) );
    tmr->setInterval( 2.5 );
    tmr->start();

    // End

function/method:

void MainWindow::update()
{
    if( yPos > hidingPoint )
    {
        ui->whatever->move( ui->whatever->x() , yPos );
        --yPos;
    }
    else
    {
        QMessageBox::about( 0 , "Out" , "I'm outta here!" );
        ui->whatever->hide();
        tmr->stop();
    }
}

Some more Information for you to read:

1

2

qt - widget - positioning

Community
  • 1
  • 1
deW1
  • 5,562
  • 10
  • 38
  • 54