Putting a Spin on Things
June 22, 2009 by Kent Hansen | Comments
Today's example shows how to reuse the statechart from the flippin' widgets example to create a widget that spins. The idea is to create a spin
state that repeatedly enters a flip
state until the speed is sufficiently slow (i.e. the widget should stop spinning). The spin
state doesn't know the internals of the flip
state; the only thing it needs to do is enter the flip
state, and have a state transition that's triggered by the flip
state's finished() signal (at which point a single flip has been performed). In other words, the SpinWidget
"embeds" the FlipWidget
's statechart in its own and builds more behavior on top. The spin
state emits the finished() signal when its work is done, so now we can build new behavior on top of that state, and so on; indeed, the top-level states of the SpinWidget
's statechart are simply an idle
state and a spin
state. Also worth noting is that all states are composed of standard QState objects (no subclassing needed).
For fun I threw in a "pulse" effect for the item under the cursor. Video:
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.5 Now!
Download the latest release here: www.qt.io/download.
Qt 6.5 is the latest Long-Term-Support release with all you need for C++ cross-platform app development.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.Henkilön Qt (@theqtcompany) jakama julkaisu