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,

    Diego


  • Moderators

    [quote author="ddonate" date="1387547070"]
    I hope I have explained my problem...
    [/quote]
    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->setFixedWidth(500);
    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();
    pLayout->setMargin(0);
    pLayout->setSpacing(0);

    pLayout->addWidget(pLabelVariable);
    pLayout->addWidget(pLabelFixed);
    pWidget->setLayout(pLayout);

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

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

    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 );
    pAni2->start();@

    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,

    Diego


Log in to reply
 

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