Drawing basic shapes on screen
In this section, we will learn how to draw simple vector shapes (line, rectangle, circle, and so on) and display text on the main window using the QPainter
class. We will also learn how to change the drawing style of the vector shapes using the QPen
class.
How to do it…
First, let's create a new Qt Widgets Application project:
- Open up
mainwindow.ui
and remove the menu bar, main tool bar, and status bar so that we get a clean, empty main window. Right-click on the bar widgets and select Remove Menu Bar from the pop-up menu: - Then, open up
mainwindow.h
and add the following code to include theQPainter
header file:#include ...
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.