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
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

States, transitions, and animations in QML


If you prefer to work with QML instead of C++, Qt also provides similar features in Qt Quick that allow you to easily animate a GUI element with the minimum lines of code. In this example, we will learn how to achieve this with QML.

How to do it…

  1. First we will create a new Qt Quick Application project and set up our user interface like so:

  2. Here is what my main.qml file looks like:

    import QtQuick 2.3
    import QtQuick.Window 2.2
    
    Window {
      visible: true
      width: 480;
      height: 320;
    
      Rectangle {
        id: background;
        anchors.fill: parent;
        color: "blue";
      }
    
      Text {
        text: qsTr("Hello World");
        anchors.centerIn: parent;
        color: "white";
        font.pointSize: 15;
      }
    }
  3. Add the color animation to the Rectangle object:

    Rectangle {
      id: background;
      anchors.fill: parent;
      color: "blue";
      SequentialAnimation on color
      {
        ColorAnimation { to: "yellow"; duration: 1000 }
        ColorAnimation { to: "red"; duration: 1000 }
        ColorAnimation ...