Results 1 to 5 of 5

Thread: Is there anything like qml's behaviours in Qt?

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Is there anything like qml's behaviours in Qt?

    I have implemented a dial (Like Dial Component in Qt SDK) in qml and it works fine but now i want to implemented it in Qt. Is there any thing(class) in Qt like behaviours in Qml (I know there is QPropertyAnimation class but with this class i need to specify its start and end points and when to start animation)
    Thanks Friends

  2. #2
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there anything like qml's behaviours in Qt?

    Something Just like behaviors in qml for example behavior in rotation or ....???No one knows??

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there anything like qml's behaviours in Qt?

    QPropertyAnimation is exactly what the Behavior element is. What Behavior does is that when you request a change of property value from X to Y, it starts an animation of the property from X to Y. So there you also specify start and end values and you also tell the animation to trigger. Only that you do that implicitly and not explicitly. With Qt/C++ you need to do that explicitly when setting the value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there anything like qml's behaviours in Qt?

    Thanks Wysota..
    By behavior qml you don't need to specify its end and start, for example in dial example of Qt SDK, there is a behavior on rotation of needle. It doesn't specify start and end point because there is not specific start and end values. I want to know if there is anything in Qt like behavior in qml or if may be QPropertyAnimation can do that without specifying start and end points???
    Thanks again

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there anything like qml's behaviours in Qt?

    Quote Originally Posted by alizadeh91 View Post
    By behavior qml you don't need to specify its end and start
    Of course you do but it is done implicitly. The start value is the current value and the end value is the value being assigned to the property.

    So if you have a setter in your class then you just need to create an animation for a smooth transition of the property value, like so:

    Qt Code:
    1. int MyClass::value() const { return m_value; }
    2.  
    3. void MyClass::setValue(int x) {
    4. if(value() == x) return;
    5. QVariantAnimation *anim = new QVariantAnimation(this);
    6. connect(anim, SIGNAL(valueChanged(QVariant)), this, SLOT(valuesetter_internal(QVariant)));
    7. anim->setStartValue(value());
    8. anim->setEndValue(x);
    9. anim->start(QAbstractAnimation::DeleteWhenStopped);
    10. }
    11.  
    12. // private slots:
    13. void MyClass::valuesetter_internal(QVariant v) {
    14. m_value = v.toInt();
    15. emit valueChanged(m_value);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Then you can just call:

    Qt Code:
    1. MyClass *obj = ...;
    2. obj->setValue(42);
    To copy to clipboard, switch view to plain text mode 
    And it will animate to the value requested. You can make it more foul proof by keeping a pointer to the animation object and adjusting the animation if someone calls setValue() before the previous animation reaches the desired value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    alizadeh91 (8th March 2012)

Similar Threads

  1. Sames executable, different behaviours...
    By high_flyer in forum Qt Programming
    Replies: 7
    Last Post: 21st March 2006, 19:33

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.