代码之家  ›  专栏  ›  技术社区  ›  juliano.net

滑动动画切换窗口或容器组件

qt
  •  0
  • juliano.net  · 技术社区  · 10 年前

    我是QT开发的新手(对它真的很陌生),我想创建一个应用程序,在表单中间显示一个文本框和一个按钮,当用户单击按钮时,文本框和按钮将向上滑动,下面将显示不同的控件。

    文本框和按钮将创建一种工具栏,动画后将显示一个内容区域。

    这是我需要的模型: https://www.fluidui.com/editor/live/preview/p_bPVFbiowoKiedzMhbQKWHdOzuDaxORFg.1408042108162

    设计师是这样的:

    QtCreator

    如何创建幻灯片动画并在动画结束时显示其他小部件?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Community CDub    8 年前

    (没有时间编写完美的代码,但你会明白的)

    你可以这样做。

    将其放在构造函数中:

        yPos = ui->whatever->y() + 1;
    
        tmr = new QTimer( );
        connect( tmr , SIGNAL( timeout( ) ) , this , SLOT( update( ) ) );
        tmr->setInterval( 2.5 );
        tmr->start();
    
        // End
    

    这是一个函数或方法:

    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();
        }
    }
    

    这将使它向下移动。

    这样它会向上移动:

    构造函数:

        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
    

    功能/方法:

    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();
        }
    }
    

    更多信息请阅读:

    1

    2

    qt - widget - positioning