Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
imageprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtGui/QGuiApplication>
5#include <QtQml/QQmlEngine>
6#include <QtQuick/QQuickImageProvider>
7#include <QtQuick/QQuickView>
8#include <QtCore/QUrl>
9#include <QtCore/QSize>
10#include <QtGui/QPixmap>
11#include <QtGui/QColor>
12
15{
16public:
21
22 QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
23 {
24 int width = 100;
25 int height = 50;
26
27 if (size)
29 QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
30 requestedSize.height() > 0 ? requestedSize.height() : height);
31 pixmap.fill(QColor(id).rgba());
32 return pixmap;
33 }
34};
37int main(int argc, char *argv[])
38{
40 QGuiApplication app(argc, argv);
44 engine->addImageProvider(QLatin1String("colors"), new ColorImageProvider);
45 view.setSource(QUrl::fromLocalFile(QStringLiteral("imageprovider-example.qml")));
46 view.show();
47 return app.exec();
48}
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
Implement this method to return the pixmap with id.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QRgb rgba() const noexcept
Returns the RGB value of the color, including its alpha.
Definition qcolor.cpp:1376
\macro qGuiApp
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition qpixmap.cpp:850
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image request...
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:20
QQmlEngine * engine() const
Returns a pointer to the QQmlEngine used for instantiating QML Components.
void setSource(const QUrl &)
Sets the source to the url, loads the QML component and instantiates it.
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
void show()
Shows the window.
Definition qwindow.cpp:2254
int main()
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
XID Pixmap
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
QApplication app(argc, argv)
[0]
widget render & pixmap
QQuickView * view
[0]
QJSEngine engine
[0]