SVG Viewer | Qt SVG | Qt 6.11.1
Description: A Qt Widgets example for rendering and viewing SVG files.

- Qt 6.11
- Qt SVG
- SVG Viewer
- Qt 6.11.1 Reference Documentation

# SVG Viewer

A Qt Widgets example for rendering and viewing SVG files.

The Qt SVG module uses QPainter to render SVG files, and this example demonstrates how to use Qt Widgets to display the rendered SVG files. The entire drawing area is places inside a QScrollArea. This way, when the user wants to zoom in an SVG image, two scrollbars automatically appear to make navigation easy. Moreover, there is an option to export the rendered SVG file to a rasterized image.

#### Rendering

To open a file, click the file icon or go to the File menu and click Open. Then, navigate through the file system and choose an SVG file. Qt SVG uses a software renderer to draw the contents of the file. This delivers pixel-perfect antialiasing and a rich set of features. But for complex SVG files, it can require significant processing on the CPU. For a hardware-accelerated SVG renderer, use VectorImage instead. Check the 2D Graphics in Qt page for the different ways to load an SVG file in Qt.

The SVG viewer provides a refresh button to reload the currently opened SVG file. The same button is available from the View menu. Futhermore, there is an Auto Refresh option in the View menu which tells the viewer to automatically re-render the file whenever it is modified.

The SVG Viewer offers three different backgrounds options: White, Black, and Chequered. Those options can be accessed from the icons in the tool bar or from the Background menu. Additionally, the same menu has a button to enable or disable the outline around the rendered SVG file.

#### Features

Since Qt 6.7, the module has gained additional features. Previously, the module supported only SVG Tiny 1.2. The Features menu allows you to enable or disable these new features. For example, you can restrict the renderer to the SVG Tiny 1.2 feature set or disable animations entirely. For a full descirption of these features, see the QtSvg::Option documentation page.

Example project @ code.qt.io