Book Image

Qt5 C++ GUI Programming Cookbook

By : Lee Zhi Eng
Book Image

Qt5 C++ GUI Programming Cookbook

By: Lee Zhi Eng

Overview of this book

With the advancement of computer technology, the software market is exploding with tons of software choices for the user, making their expectations higher in terms of functionality and the look and feel of the application. Therefore, improving the visual quality of your application is vital in order to overcome the market competition and stand out from the crowd. This book will teach you how to develop functional and appealing software using Qt5 through multiple projects that are interesting and fun. This book covers a variety of topics such as look-and-feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. You will learn tons of useful information, and enjoy the process of working on the creative projects provided in this book
Table of Contents (16 chapters)
Qt5 C++ GUI Programming Cookbook
About the Author
About the Reviewer

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:

  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 do within each state, which in this case will be to change the label's text, as well as the button's position and size:

    QState *s1 = new QState();
    s1->assignProperty(ui->stateLabel, "text", "Current state: 1");
    s1->assignProperty(ui->pushButton, "geometry", QRect(50, 200, 100, 50));
    QState *s2 = new QState();