| 1 |
// Copyright (C) 2025 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only |
| 3 |
/*! |
| 4 |
\title SVG Viewer |
| 5 |
\example svgviewer |
| 6 |
\image svgviewer-example.png |
| 7 |
\brief A Qt Widgets example for rendering and viewing SVG files. |
| 8 |
\examplecategory {Graphics} |
| 9 |
|
| 10 |
The \l{Qt SVG} module uses \l{QPainter} to render SVG files, and this example demonstrates how to use Qt Widgets |
| 11 |
to display the rendered SVG files. The entire drawing area is places inside a \l{QScrollArea}. This way, |
| 12 |
when the user wants to zoom in an SVG image, two scrollbars automatically appear to make navigation easy. |
| 13 |
Moreover, there is an option to export the rendered SVG file to a rasterized image. |
| 14 |
|
| 15 |
\section1 Rendering |
| 16 |
|
| 17 |
To open a file, click the file icon or go to the \e{File menu} and click Open. Then, navigate through |
| 18 |
the file system and choose an SVG file. \l{Qt SVG} uses a software renderer to draw the contents of the file. |
| 19 |
This delivers pixel-perfect antialiasing and a rich set of features. But for complex SVG files, it can require |
| 20 |
significant processing on the CPU. For a hardware-accelerated SVG renderer, use \l{VectorImage} instead. Check |
| 21 |
the \l{2D Graphics in Qt} page for the different ways to load an SVG file in Qt. |
| 22 |
|
| 23 |
The SVG viewer provides a refresh button to reload the currently opened SVG file. The same button is available from |
| 24 |
the \e{View menu}. Futhermore, there is an \b{Auto Refresh} option in the \e{View menu} which tells the viewer to |
| 25 |
automatically re-render the file whenever it is modified. |
| 26 |
|
| 27 |
The SVG Viewer offers three different backgrounds options: \b{White}, \b{Black}, and \b{Chequered}. Those options |
| 28 |
can be accessed from the icons in the tool bar or from the \e{Background menu}. Additionally, the same menu |
| 29 |
has a button to enable or disable the outline around the rendered SVG file. |
| 30 |
|
| 31 |
\section1 Features |
| 32 |
|
| 33 |
\b{Since Qt 6.7}, the module has gained additional features. Previously, the module supported only SVG Tiny 1.2. |
| 34 |
The \e{Features menu} allows you to enable or disable these new features. For example, you can restrict the |
| 35 |
renderer to the SVG Tiny 1.2 feature set or disable animations entirely. For a full descirption of these features, |
| 36 |
see the \l{QtSvg::Option} documentation page. |
| 37 |
*/ |