Displaying a 2D graphical image
In this recipe, you will learn to display a 2D graphical image. We assume that you have a graphical image by the name scene.jpg
on your machine, and you will learn how it is displayed on the form. The focus of this recipe is to understand how the Graphics View
widget is used to display an image.
How to do it...
The procedure for displaying graphics is very simple. You first need to create an object of QGraphicsScene
, which in turn makes use of the QGraphicsView
class to show its contents. Graphical items, including images, are then added to the QGraphicsScene
class by invoking the addItem
method of the QGraphicsScene
class. Here are the steps to display a 2D graphical image on the screen:
- Create a new application based on the
Dialog without Buttons
template. - Drag and drop a
Graphics View
widget onto it. - Save the application with the name
demoGraphicsView.ui
. The form will appear as shown in the following screenshot:
The pyuic5
command utility converts the.ui
(XML...