Important: Please read the Qt Code of Conduct -

QPropertyAnimation problem: Variable widget height (upwards)

  • Hi,

    I am trying to do a QPropertyAnimation but faced some problems.

    My target is a main widget with 2 parts: bottom & top, with no spacing between them.

    Bottom: fixed size
    Top: same width as bottom and animated height but UPWARDS (from 0px, i.e, initially "hidden"). Like a 'popup'

    Animation will start with a button:
    1st click: Top widget "goes up" from 0px to 100px in top of bottom widget
    2nd click: Top widget" goes down" from 100px to 0px in top of bottom widget ("hidden" again)

    I have tried using 'height' property, but no success since top widget increased its height downwards

    I have tried using 'geometry' property, using negative values since top widget position is referenced to its parent (main widget). This way my top widget go upwards (ok), but main widget does NOT resize, so top widget is NOT seen... I thought I could use 'valueChanged' signal from QPropertyAnimation (top widget height values: 0 -> 100) to change main widget geometry, but no success.

    I hope I have explained my problem...

    Any idea? Thanks in advance,


  • Moderators

    [quote author="ddonate" date="1387547070"]
    I hope I have explained my problem...
    yes, but i hardly got you :)
    Please show some code anyway.

  • Hi,

    Thanks for your response.

    Last code I have tried is:

    @// TOP FIXED WIDGET ------------------------------------
    QLabel* pLabelFixed = new QLabel( "fixed" );
    pLabelFixed->setFixedHeight( 50 );
    pLabelFixed->setFrameStyle( QFrame::StyledPanel );

    // BOTTOM VARIABLE -------------------------------------
    QLabel* pLabelVariable = new QLabel( "variable" );
    pLabelVariable->setFrameStyle( QFrame::StyledPanel );
    pLabelVariable->resize(500, 0);

    // WHOLE WIDGET ---------------------------------------
    QWidget* pWidget = new QWidget( NULL, Qt::Popup );
    pWidget->setFixedWidth( 500 );

    QVBoxLayout* pLayout = new QVBoxLayout();


    QPoint pos( 500,500 );
    pWidget->move( pos );

    // ANIMATIONS ------------------------------------------
    QPropertyAnimation* pAni = new QPropertyAnimation( pLabelVariable, "minimumHeight" );
    pAni->setStartValue( 0 );
    pAni->setEndValue( 50 );
    pAni->setDuration( 1000 );

    QPropertyAnimation* pAni2 = new QPropertyAnimation( pWidget, "geometry" );
    pAni2->setStartValue( QRect( QPoint(500,500), QSize(500,50) ) );
    pAni2->setEndValue( QRect( QPoint(500,450), QSize(500,100) ) );
    pAni2->setDuration( 1000 );

    and the effect is what i need... BUT the mixed animation flickers too much. I think it is logic, since 1st animation makes TopWidget to downwards, while 2nd animation forces the whole widget to move upwards. It seems to cause "painting problems"...

    Any idea or another solution?

    Thanks in advance,


Log in to reply