我正在尝试学习Qt框架。我的QStateMachine代码做了正确的事情(按下按钮使聊天窗口弹出更改大小)。 我无法改变动画的速度以获得良好的视觉过渡。 有什么建议吗?
以下是代码:
MainWindow::MainWindow()
{
widget.setupUi( this );
// chat window - Chat button opens
ChatWindowClosedState = new QState();
ChatWindowOpenState = new QState();
ChatWindowOpenGeometry = widget.groupBox->geometry();
ChatWindowClosedGeometry = widget.pushButton->geometry();
ChatWindowClosedGeometry.translate( -ChatWindowClosedGeometry.width(), 0 );
ChatWindowClosedState->assignProperty( widget.groupBox, "geometry", ChatWindowClosedGeometry );
ChatWindowOpenState->assignProperty( widget.groupBox, "geometry", ChatWindowOpenGeometry );
ChatWindowCloseTransition = ChatWindowClosedState->addTransition( widget.pushButton, SIGNAL( clicked() ), ChatWindowOpenState );
ChatWindowCloseAnimation = new QPropertyAnimation( widget.pushButton, "geometry" );
ChatWindowCloseAnimation->setDuration( 5000 );
ChatWindowCloseTransition->addAnimation( ChatWindowCloseAnimation );
ChatWindowOpenTransition = ChatWindowOpenState->addTransition( widget.pushButton, SIGNAL( clicked() ), ChatWindowClosedState );
ChatWindowOpenAnimation = new QPropertyAnimation( widget.pushButton, "geometry" );
ChatWindowOpenAnimation->setDuration( 5000 );
ChatWindowOpenTransition->addAnimation( ChatWindowOpenAnimation );
machine = new QStateMachine( this );
machine->addState( ChatWindowClosedState );
machine->addState( ChatWindowOpenState );
machine->setInitialState( ChatWindowClosedState );
machine->start();
}
答案 0 :(得分:0)
代码
ChatWindowOpenAnimation = new QPropertyAnimation( widget.pushButton, "geometry" );
应该是
ChatWindowOpenAnimation = new QPropertyAnimation( widget.groupBox, "geometry" );
动画正在应用于错误的小部件。