Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsvgwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qsvgwidget.h"
5
6#include <qsvgrenderer.h>
7
8#include "qstyleoption.h"
9#include "qpainter.h"
10#include <QtWidgets/private/qwidget_p.h>
11
13
45{
46 Q_DECLARE_PUBLIC(QSvgWidget)
47public:
49};
50
56{
57 d_func()->renderer = new QSvgRenderer(this);
58 QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()),
59 this, SLOT(update()));
60}
61
68{
69 d_func()->renderer = new QSvgRenderer(file, this);
70 QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()),
71 this, SLOT(update()));
72}
73
78{
79
80}
81
86{
87 Q_D(const QSvgWidget);
88 return d->renderer;
89}
90
91
96{
97 Q_D(const QSvgWidget);
98 if (d->renderer->isValid())
99 return d->renderer->defaultSize();
100 else
101 return QSize(128, 64);
102}
103
104
109{
110 Q_D(QSvgWidget);
112 opt.initFrom(this);
113 QPainter p(this);
115 d->renderer->render(&p);
116}
117
122{
123 Q_D(const QSvgWidget);
124 d->renderer->load(file);
125}
126
131{
132 Q_D(const QSvgWidget);
133 d->renderer->load(contents);
134}
135
\inmodule QtCore
Definition qbytearray.h:57
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
@ PE_Widget
Definition qstyle.h:148
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
\inmodule QtSvg
QSvgRenderer * renderer
\inmodule QtSvgWidgets
Definition qsvgwidget.h:19
QSvgWidget(QWidget *parent=nullptr)
Constructs a new SVG display widget with the given parent.
QSize sizeHint() const override
\reimp
void load(const QString &file)
Loads the contents of the specified SVG file and updates the widget.
QSvgRenderer * renderer() const
Returns the renderer used to display the contents of the widget.
void paintEvent(QPaintEvent *event) override
\reimp
~QSvgWidget()
Destroys the widget.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QStyle * style() const
Definition qwidget.cpp:2607
QStyleOptionButton opt
Combined button and popup list for selecting options.
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLfloat GLfloat p
[1]
QFile file
[0]
QSvgRenderer * renderer
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent