State machines in Qt

State machines can be used for many purposes, but in this chapter we will only cover topics related to animation.

How to do it…

  1. First, we will set up a new user interface for our example program, which looks like this:
    How to do it…
  2. Next, we will include some headers in our source code:
    #include <QStateMachine>
    #include <QPropertyAnimation>
    #include <QEventTransition>
  3. After that, in our main window's constructor, add the following code to create a new state machine and two states, which we will be using later:
    QStateMachine *machine = new QStateMachine(this);
    QState *s1 = new QState();
    QState *s2 = new QState();
  4. Then, we will define what we should ...

Get Qt5 C++ GUI Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.