QPropertyAnimation can't used to Qtabwidget



  • I want to hide the Qtabwidget
    So I used QPropertyAnimation to make Qtabwidget's width is 0 in 400ms
    but the tabwidget will rebound
    the tabwidget's sizepolicy is expanding
    other widget is okay,like Qframe,buton.....
    I don't know how to do that

    //frame_2 has the tabwidget
        QPropertyAnimation *animation= new QPropertyAnimation(ui->frame_2,"geometry");
        animation->setDuration(400);
        animation->setStartValue(ui->frame_2->geometry());
        if(expanded){
            animation->setEndValue(QRect(0,0, 0, ui->frame_2->height()));
        }
        else {
            animation->setEndValue(QRect(0,0, 500, ui->frame_2->height()));
        }
    


  • @hezf
    Hi,
    Do you have a layout for the QTabWidget?
    If you have a layout, the QTabWidget will re-arranged by layout.



  • @Devopia53
    yes,I used layout
    but why others is okay?like qpushbutton...
    and if I don't use a layout ,what Can I do for layout ?
    Thank you for your answer.



  • @hezf
    If parent widget changed(like size), other widgets will re-arranged also.
    You should remove layout of QFrame and then use hide()/show() for QFrame.

    Ex)

    [...] 
    // set up animation, frame has the QTabWidget
        animation= new QPropertyAnimation(ui->frame, "geometry");
        animation->setDuration(400);
        animation->setStartValue(ui->frame->geometry());
        animation->setEndValue(QRect(ui->frame->x(), ui->frame->y(), 0, ui->frame->height()));
        connect(animation, &QPropertyAnimation::finished,
                [&]{ if (animation->direction() == QPropertyAnimation::Forward) {
                ui->frame->hide();
                animation->setDirection(QPropertyAnimation::Backward);
            }
            else
                animation->setDirection(QPropertyAnimation::Forward);
        });
    
    [...]
    
    // start animation
        if (animation->direction() == QPropertyAnimation::Backward)
            ui->frame->show();
        animation->start();
    
    


  • @Devopia53
    thank you,I will try it.



  • @Devopia53
    Hi,
    Can you send me the project?
    hezf@boltit.cn


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.