Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Qt5 C++ GUI Programming Cookbook

You're reading from   Qt5 C++ GUI Programming Cookbook Design and build a functional, appealing, and user-friendly graphical user interface

Arrow left icon
Product type Paperback
Published in Jul 2016
Publisher Packt
ISBN-13 9781783280278
Length 300 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Lee Zhi Eng Lee Zhi Eng
Author Profile Icon Lee Zhi Eng
Lee Zhi Eng
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Look and Feel Customization FREE CHAPTER 2. States and Animations 3. QPainter and 2D Graphics 4. OpenGL Implementation 5. Building a Touch Screen Application with Qt5 6. XML Parsing Made Easy 7. Conversion Library 8. Accessing Databases 9. Developing a Web Application Using Qt Web Engine Index

Rendering 2D shapes

Since we have already learned how to draw our first rectangle on the screen, we will further enhance it in this section. We will take the previous example and continue from there.

How to do it…

  1. First, go to the paintGL() function in mainwindow.cpp and replace the quad in the previous example with new code. This time, we draw a quad together with a triangle:
    void MainWindow::paintGL()
    {
      // Initialize clear color (cornflower blue)
      glClearColor(0.39f, 0.58f, 0.93f, 1.f);
    
      // Clear color buffer
      glClear(GL_COLOR_BUFFER_BIT);
    
      glBegin(GL_QUADS);
      glVertex2f(-0.5f, -0.5f);
      glVertex2f(0.5f, -0.5f);
      glVertex2f(0.5f, 0.5f);
      glVertex2f(-0.5f, 0.5f);
      glEnd();
    
      glBegin(GL_QUADS);
        glColor3f(1.f, 0.f, 0.f); glVertex2f(-0.8f, -0.8f);
        glColor3f(1.f, 1.f, 0.f); glVertex2f(0.3f, -0.8f);
        glColor3f(0.f, 1.f, 0.f); glVertex2f(0.3f, 0.3f);
        glColor3f(0.f, 0.f, 1.f); glVertex2f(-0.8f, 0.3f);
      glEnd();
    
      glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime