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

Hello world!

In this recipe, we will learn about the pipeline of OpenGL and how to render a simple shape to the window. We will continue from the example project used in the previous recipe.

How to do it…

  1. First of all, go to mainwindow.h and add the following headers at the top of the source code:

    #include <QSurfaceFormat>
    #include <QOpenGLFunctions>
    #include <QtOpenGL>
    #include <GL/glu.h>
  2. Next, declare two private variables in mainwindow.h:

      QOpenGLContext* context;
      QOpenGLFunctions* openGLFunctions;
  3. After that, move over to mainwindow.cpp and set the surface format to compatibility profile. We also set the OpenGL version to 2.1 and create the OpenGL context using the format we just declared. Then, use the context we just created to access the OpenGL functions that are relevant only to the OpenGL version we have just set, by calling context->functions():

    MainWindow::MainWindow(QWidget *parent)
      QSurfaceFormat format...