Results 1 to 6 of 6

Thread: QPropertyAnimation problem: Variable widget height (upwards)

  1. #1
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPropertyAnimation problem: Variable widget height (upwards)

    You most likely have to increase the size of the window itself, i.e. decrease its y value and at the same time increasing its height.

    The layout should then resize the top widget accordingly since the other ones is fixed in height.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPropertyAnimation problem: Variable widget height (upwards)

    Hi,

    Thanks for your response.

    I have tried this code:

    Qt Code:
    1. // TOP FIXED WIDGET ------------------------------------
    2. QLabel* pLabelFixed = new QLabel( "fixed" );
    3. pLabelFixed->setFixedHeight( 50 );
    4. pLabelFixed->setFixedWidth(500);
    5. pLabelFixed->setFrameStyle( QFrame::StyledPanel );
    6.  
    7. // BOTTOM VARIABLE -------------------------------------
    8. QLabel* pLabelVariable = new QLabel( "variable" );
    9. pLabelVariable->setFrameStyle( QFrame::StyledPanel );
    10. pLabelVariable->resize(500, 0);
    11.  
    12. // WHOLE WIDGET ---------------------------------------
    13. QWidget* pWidget = new QWidget( NULL, Qt::Popup );
    14. pWidget->setFixedWidth( 500 );
    15.  
    16. QVBoxLayout* pLayout = new QVBoxLayout();
    17. pLayout->setMargin(0);
    18. pLayout->setSpacing(0);
    19.  
    20. pLayout->addWidget(pLabelVariable);
    21. pLayout->addWidget(pLabelFixed);
    22. pWidget->setLayout(pLayout);
    23.  
    24. QPoint pos( 500,500 );
    25. pWidget->move( pos );
    26. pWidget->show();
    27.  
    28. // ANIMATIONS ------------------------------------------
    29. QPropertyAnimation* pAni = new QPropertyAnimation( pLabelVariable, "minimumHeight" );
    30. pAni->setStartValue( 0 );
    31. pAni->setEndValue( 50 );
    32. pAni->setDuration( 1000 );
    33. pAni->start();
    34.  
    35. QPropertyAnimation* pAni2 = new QPropertyAnimation( pWidget, "geometry" );
    36. pAni2->setStartValue( QRect( QPoint(500,500), QSize(500,50) ) );
    37. pAni2->setEndValue( QRect( QPoint(500,450), QSize(500,100) ) );
    38. pAni2->setDuration( 1000 );
    39. pAni2->start();
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPropertyAnimation problem: Variable widget height (upwards)

    My suggestion would be to change the windows geometry.
    That allows you to set a new position (moving up) and a new height.

    Since the contents are layouted, they will be resized automatically, i.e. the variable sized label will expand.

    Cheers,
    _

  5. #5
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPropertyAnimation problem: Variable widget height (upwards)

    Hi,

    I understand your idea, it seems to be right. But when I try to apply that it does not work for me (altough when animation is finished it looks ok). I change main widget geometry (position & size), but:
    - main widget moves a little upwards at the beginning
    - variable sized label does not start with height = 0

    I supponse I am doing sth wrong.

    Animation code:

    Qt Code:
    1. QPoint pointIni = QPoint(500,500);
    2. QPoint pointEnd = QPoint(500,450);
    3.  
    4. QSize sizeIni = QSize(300, 50);
    5. QSize sizeEnd = QSize(300, 100);
    6.  
    7. QPropertyAnimation* pAni2 = new QPropertyAnimation( pWidget, "geometry" );
    8. pAni2->setStartValue( QRect( pointIni, sizeIni ) );
    9. pAni2->setEndValue( QRect( pointEnd, sizeEnd ) );
    10. pAni2->setDuration( 1000 );
    11. pAni2->start();
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot,

    Diego

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPropertyAnimation problem: Variable widget height (upwards)

    Maybe you are not using the correct values.

    See http://qt-project.org/doc/qt-5.0/qtw...indow-geometry for the different geometry types on top level windows.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 14th October 2011, 10:34
  2. QPropertyAnimation show the Widget before start the animation
    By rperezalejo in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2011, 02:26
  3. Widget Height and Width
    By in_dbasu in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2011, 08:44
  4. Central Widget Max Height
    By fruzzo in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2011, 18:26
  5. Replies: 2
    Last Post: 11th November 2009, 08:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.