Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
13
//![0]
14
class
ColorImageProvider
:
public
QQuickImageProvider
15
{
16
public
:
17
ColorImageProvider
()
18
:
QQuickImageProvider
(
QQuickImageProvider
::
Pixmap
)
19
{
20
}
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)
28
*size = QSize(width, height);
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
};
35
//![0]
36
//![1]
37
int
main
(
int
argc,
char
*argv[])
38
{
39
//![1]
40
QGuiApplication app(argc, argv);
41
//![2]
42
QQuickView view;
43
QQmlEngine *engine = view.engine();
44
engine->addImageProvider(QLatin1String(
"colors"
),
new
ColorImageProvider
);
45
view.setSource(QUrl::fromLocalFile(QStringLiteral(
"imageprovider-example.qml"
)));
46
view.show();
47
return
app.exec();
48
}
49
//![2]
ColorImageProvider
[0]
Definition
imageprovider.cpp:15
ColorImageProvider::requestPixmap
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
Implement this method to return the pixmap with id.
Definition
imageprovider.cpp:22
ColorImageProvider::ColorImageProvider
ColorImageProvider()
Definition
imageprovider.cpp:17
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtdeclarative
src
quick
doc
snippets
imgprovider
imageprovider.cpp
Generated on
for Qt by
1.14.0