7#include <QtWidgets/private/qwidgetrepaintmanager_p.h>
9#include "private/qquickwindow_p.h"
10#include "private/qquickitem_p.h"
11#include "private/qquickitemchangelistener_p.h"
12#include "private/qquickrendercontrol_p.h"
13#include "private/qsgrhisupport_p.h"
15#include "private/qsgsoftwarerenderer_p.h"
17#include <private/qqmldebugconnector_p.h>
18#include <private/qquickprofiler_p.h>
19#include <private/qqmldebugserviceinterfaces_p.h>
21#include <QtQml/qqmlengine.h>
22#include <private/qqmlengine_p.h>
23#include <QtCore/qbasictimer.h>
24#include <QtGui/QOffscreenSurface>
25#include <QtGui/private/qguiapplication_p.h>
26#include <QtGui/qpa/qplatformintegration.h>
28#include <QtGui/QPainter>
30#include <QtQuick/QSGRendererInterface>
33#if QT_CONFIG(messagebox)
34# include <QtWidgets/QMessageBox>
36# include <QtCore/QLibraryInfo>
37# include <QtCore/qt_windows.h>
40#include <QtQuick/qquickgraphicsdevice.h>
41#include <QtQuick/qquickrendertarget.h>
43#include "private/qwidget_p.h"
45#if QT_CONFIG(graphicsview)
46#include <QtWidgets/qgraphicsscene.h>
47#include <QtWidgets/qgraphicsview.h>
93#if QT_CONFIG(graphicsview)
95 auto *
proxy = (widgetd && widgetd->
extra) ? widgetd->
extra->proxyWidget :
nullptr;
99 if (
view->window()->windowHandle() ==
w)
119 *
offset =
d->m_quickWidget->mapTo(
d->m_quickWidget->window(),
QPoint());
122#if QT_CONFIG(graphicsview)
124 if (widgetd->
extra) {
125 if (
auto proxy = widgetd->
extra->proxyWidget) {
129 if (!views.isEmpty()) {
132 auto candidateView = views.
first();
133 result = candidateView->window()->windowHandle();
140 result =
d->m_quickWidget->window()->windowHandle();
157#if QT_CONFIG(accessibility)
158 QAccessible::installFactory(&qAccessibleQuickWidgetFactory);
191 qWarning(
"QQuickWidget is not supported on this platform.");
199#if QT_CONFIG(quick_draganddrop)
200 q->setAcceptDrops(
true);
273 , eventPending(
false)
274 , updatePending(
false)
276 , requestedSamples(0)
277 , useSoftwareRenderer(
false)
278 , forceFullUpdate(
false)
287 q->destroyFramebufferObject();
309 q->continueExecute();
312 q,
SLOT(continueExecute()));
318 const QRectF &oldGeometry)
335 q->createFramebufferObject();
339 qWarning(
"QQuickWidget: Attempted to render scene with no rhi");
358 qWarning(
"QQuickWidget: Failed to begin recording a frame");
383 softwareRenderer->markDirty();
403#if QT_CONFIG(graphicsview)
404 if (
q->window()->graphicsProxyWidget())
405 QWidgetPrivate::nearestGraphicsProxyWidget(
q)->update();
432 cb->resourceUpdate(resUpd);
441 return wrapperImage.
copy();
613 setMouseTracking(
true);
642 setMouseTracking(
true);
704 if (
d->component &&
d->component->isError()) {
714 d->setRootObject(
item);
751 return d->engine.data()->rootContext();
796 if (!
d->engine && !
d->source.isEmpty())
820 errs =
d->component->errors();
822 if (!
d->engine && !
d->source.isEmpty()) {
856 if (
d->resizeMode ==
mode)
866 d->resizeMode =
mode;
892 if (newSize !=
q->size()) {
905 if (needToUpdateWidth && needToUpdateHeight) {
910 const QSizeF newSize(
q->width(),
q->height());
914 }
else if (needToUpdateWidth) {
915 const int newWidth =
q->width();
919 }
else if (needToUpdateHeight) {
920 const int newHeight =
q->height();
947 int widthCandidate = -1;
948 int heightCandidate = -1;
953 if (widthCandidate > 0) {
956 if (heightCandidate > 0) {
971 const bool signalConnected =
q->isSignalConnected(errorSignal);
973 emit q->sceneGraphError(QQuickWindow::ContextNotAvailable, translatedMessage);
975#if defined(Q_OS_WIN) && QT_CONFIG(messagebox)
979 if (!signalConnected)
1007 QRhi *tlwRhi =
nullptr;
1009 tlwRhi = repaintManager->rhi();
1010 if (tlwRhi &&
rhi != tlwRhi)
1018 if (!onlyNeedsSgInit) {
1023 rhi = repaintManager->rhi();
1041 qWarning(
"The top-level window is not using the expected graphics API for composition, "
1042 "'%s' is not compatible with this QQuickWidget",
1051#if QT_CONFIG(vulkan)
1052 if (
QWindow *
w =
q->window()->windowHandle())
1058 qWarning(
"QQuickWidget: Failed to get a QRhi from the top-level widget's window");
1062void QQuickWidget::createFramebufferObject()
1068 if (
size().isEmpty())
1075 d->offscreenWindow->setGeometry(globalPos.
x(), globalPos.
y(),
width(),
height());
1077 if (
d->useSoftwareRenderer) {
1081 d->forceFullUpdate =
true;
1086 qWarning(
"QQuickWidget: Attempted to create output texture with no QRhi");
1099 if (!
d->outputTexture) {
1101 if (!
d->outputTexture->create()) {
1102 qWarning(
"QQuickWidget: failed to create output texture of size %dx%d",
1106 if (!
d->depthStencil) {
1108 if (!
d->depthStencil->create()) {
1109 qWarning(
"QQuickWidget: failed to create depth/stencil buffer of size %dx%d and sample count %d",
1113 if (
samples > 1 && !
d->msaaBuffer) {
1115 if (!
d->msaaBuffer->create()) {
1116 qWarning(
"QQuickWidget: failed to create multisample renderbuffer of size %dx%d and sample count %d",
1131 d->rt =
d->rhi->newTextureRenderTarget(rtDesc);
1132 d->rtRp =
d->rt->newCompatibleRenderPassDescriptor();
1133 d->rt->setRenderPassDescriptor(
d->rtRp);
1136 if (
d->outputTexture->pixelSize() != fboSize) {
1137 d->outputTexture->setPixelSize(fboSize);
1138 if (!
d->outputTexture->create()) {
1139 qWarning(
"QQuickWidget: failed to create resized output texture of size %dx%d",
1142 d->depthStencil->setPixelSize(fboSize);
1143 if (!
d->depthStencil->create()) {
1144 qWarning(
"QQuickWidget: failed to create resized depth/stencil buffer of size %dx%d",
1147 if (
d->msaaBuffer) {
1148 d->msaaBuffer->setPixelSize(fboSize);
1149 if (!
d->msaaBuffer->create()) {
1150 qWarning(
"QQuickWidget: failed to create resized multisample renderbuffer of size %dx%d",
1158 d->renderControl->setSamples(
samples);
1163 Q_ASSERT(!
d->offscreenWindow->handle());
1166void QQuickWidget::destroyFramebufferObject()
1170 if (
d->useSoftwareRenderer) {
1179 delete d->depthStencil;
1180 d->depthStencil =
nullptr;
1181 delete d->msaaBuffer;
1182 d->msaaBuffer =
nullptr;
1183 delete d->outputTexture;
1184 d->outputTexture =
nullptr;
1190 return d->resizeMode;
1196void QQuickWidget::continueExecute()
1201 if (
d->component->isError()) {
1213 if (
d->component->isError()) {
1223 d->setRootObject(
obj);
1240 qWarning() <<
"QQuickWidget does not support using windows as a root item." <<
Qt::endl
1242 <<
"If you wish to create your root window from QML, consider using QQmlApplicationEngine instead." <<
Qt::endl;
1244 qWarning() <<
"QQuickWidget only supports loading of root objects that derive from QQuickItem." <<
Qt::endl
1246 <<
"Ensure your QML code is written for QtQuick 2, and uses a root that is or" <<
Qt::endl
1247 <<
"inherits from QtQuick's Item (not a Timer, QtObject, etc)." <<
Qt::endl;
1278 config.setDebugLayer(debugLayerRequested);
1285 if (!
q->isWindow() &&
q->internalWinId()) {
1286 qWarning() <<
"QQuickWidget cannot be used as a native child widget."
1287 <<
"Consider setting Qt::AA_DontCreateNativeWidgetSiblings";
1307 if (!
e ||
e->timerId() ==
d->resizetimer.timerId()) {
1309 d->resizetimer.stop();
1310 }
else if (
e->timerId() ==
d->updateTimer.timerId()) {
1311 d->eventPending =
false;
1312 d->updateTimer.stop();
1313 if (
d->updatePending)
1314 d->renderSceneGraph();
1325 QSize rootObjectSize =
d->rootObjectSize();
1326 if (rootObjectSize.
isEmpty()) {
1329 return rootObjectSize;
1343 return d->initialSize;
1368 if (
e->size().isEmpty()) {
1370 d->fakeHidden =
true;
1374 bool needsSync =
false;
1375 if (
d->fakeHidden) {
1377 d->fakeHidden =
false;
1382 if (
d->useSoftwareRenderer) {
1385 createFramebufferObject();
1391 if (!
d->outputTexture && !
d->offscreenWindow->isSceneGraphInitialized())
1395 createFramebufferObject();
1401 d->initializeWithRhi();
1405 qWarning(
"QQuickWidget::resizeEvent() no QRhi");
1410 d->render(needsSync);
1426 return event.isAccepted();
1460 QMouseEvent mappedEvent(
e->type(),
e->position(),
e->position(),
e->globalPosition(),
1461 e->button(),
e->buttons(),
e->modifiers(),
e->source());
1471 e->button(),
e->buttons());
1476 e->button(),
e->buttons(),
e->modifiers(),
e->source());
1479 QMouseEvent mappedEvent(
e->type(),
e->position(),
e->position(),
e->globalPosition(),
1480 e->button(),
e->buttons(),
e->modifiers(),
e->source());
1488 bool shouldTriggerUpdate =
true;
1490 if (!
d->useSoftwareRenderer) {
1491 d->initializeWithRhi();
1493 if (
d->offscreenWindow->isSceneGraphInitialized()) {
1494 shouldTriggerUpdate =
false;
1503 if (!
d->eventPending &&
d->updatePending) {
1504 d->updatePending =
false;
1510 if (shouldTriggerUpdate)
1514 d->offscreenWindow->setVisible(
true);
1523 if (!
d->offscreenWindow->isPersistentSceneGraph())
1524 d->invalidateRenderControl();
1526 d->offscreenWindow->setVisible(
false);
1528 service->setParentWindow(
d->offscreenWindow,
d->offscreenWindow);
1538 QMouseEvent mappedEvent(
e->type(),
e->position(),
e->position(),
e->globalPosition(),
1539 e->button(),
e->buttons(),
e->modifiers(),
e->source());
1551 QMouseEvent mappedEvent(
e->type(),
e->position(),
e->position(),
e->globalPosition(),
1552 e->button(),
e->buttons(),
e->modifiers(),
e->source());
1557#if QT_CONFIG(wheelevent)
1559void QQuickWidget::wheelEvent(QWheelEvent *
e)
1563 e->angleDelta().x(),
e->angleDelta().y());
1576 d->offscreenWindow->focusInEvent(
event);
1585 d->offscreenWindow->focusOutEvent(
event);
1610 if (
e->queries() &
query) {
1629 switch (
e->type()) {
1644 auto deliveredPoints = pointerEvent->
points();
1645 for (
auto &point : deliveredPoints) {
1647 point.setAccepted(
true);
1670 d->invalidateRenderControl();
1671 d->deviceLost =
true;
1676 d->handleWindowChange();
1682 if (
d->offscreenWindow)
1683 d->offscreenWindow->setScreen(newScreen);
1687 if (
d->useSoftwareRenderer ||
d->outputTexture) {
1690 createFramebufferObject();
1693 if (
d->offscreenWindow) {
1700 d->updatePosition();
1725#if QT_CONFIG(quick_draganddrop)
1728void QQuickWidget::dragEnterEvent(QDragEnterEvent *
e)
1733 d->offscreenWindow->event(
e);
1738void QQuickWidget::dragMoveEvent(QDragMoveEvent *
e)
1743 d->offscreenWindow->event(
e);
1747void QQuickWidget::dragLeaveEvent(QDragLeaveEvent *
e)
1750 d->offscreenWindow->event(
e);
1754void QQuickWidget::dropEvent(QDropEvent *
e)
1757 d->offscreenWindow->event(
e);
1765void QQuickWidget::triggerUpdate()
1768 d->updatePending =
true;
1769 if (!
d->eventPending) {
1778 const int exhaustDelay = 5;
1780 d->eventPending =
true;
1808 d->requestedSamples = newFormat.
samples();
1811 d->offscreenWindow->setFormat(newFormat);
1824 return d->offscreenWindow->format();
1850 d->offscreenWindow->setColor(
color);
1874 return d->offscreenWindow;
1883 if (
d->useSoftwareRenderer) {
1885 d->updateRegion =
d->updateRegion.united(
event->region());
1886 if (
d->updateRegion.isNull()) {
1894 d->updateRegion.swap(targetRegion);
1895 for (
auto targetRect : targetRegion) {
1903void QQuickWidget::propagateFocusObjectChanged(
QObject *focusObject)
1909 emit window->focusObjectChanged(focusObject);
1914#include "moc_qquickwidget_p.cpp"
1916#include "moc_qquickwidget.cpp"
void setConfig(const QPlatformBackingStoreRhiConfig &config)
void setFormat(const QSurfaceFormat &format)
static QRhi::Implementation apiToRhiBackend(QPlatformBackingStoreRhiConfig::Api api)
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
The QColor class provides colors based on RGB, HSV or CMYK values.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QString applicationName
the name of this application
@ WindowAboutToChangeInternal
The QFocusEvent class contains event parameters for widget focus events.
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item's coordinate system, to the scene's coordinate system,...
QRectF mapRectToScene(const QRectF &rect) const
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
static QPlatformIntegration * platformIntegration()
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
The QHideEvent class provides an event which is sent after a widget is hidden.
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
@ Format_RGBA8888_Premultiplied
@ Format_ARGB32_Premultiplied
QImage mirrored(bool horizontally=false, bool vertically=true) const &
The QKeyEvent class describes a key event.
int key() const
Returns the code of the key that was pressed or released.
static bool isDebugBuild() noexcept Q_DECL_CONST_FUNCTION
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void void Q_DECL_COLD_FUNCTION void warning(const char *msg,...) const Q_ATTRIBUTE_FORMAT_PRINTF(2
Logs a warning message specified with format msg.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
qreal devicePixelRatio() const
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
@ NeedsPremultipliedAlphaBlending
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
A base class for pointer events.
QObject * exclusiveGrabber(const QEventPoint &point) const
Returns the object which has been set to receive all future update events and the release event conta...
const QList< QEventPoint > & points() const
Returns a list of points in this pointer event.
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
The QQmlComponent class encapsulates a QML component definition.
bool isLoading() const
Returns true if status() == QQmlComponent::Loading.
The QQmlContext class defines a context within a QML engine.
The QQmlEngine class provides an environment for instantiating QML components.
QQmlIncubationController * incubationController() const
Returns the currently set incubation controller, or 0 if no controller has been set.
void setIncubationController(QQmlIncubationController *)
Sets the engine's incubation controller.
The QQmlError class encapsulates a QML error.
bool isDebugLayerEnabled() const
static QQuickGraphicsDevice fromRhi(QRhi *rhi)
virtual void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setSize(const QSizeF &size)
void setParentItem(QQuickItem *parent)
qreal width
This property holds the width of this item.
qreal height
This property holds the height of this item.
static QQuickRenderControlPrivate * get(QQuickRenderControl *renderControl)
The QQuickRenderControl class provides a mechanism for rendering the Qt Quick scenegraph onto an offs...
bool initialize()
Initializes the scene graph resources.
void endFrame()
Specifies the end of a graphics frame.
void render()
Renders the scenegraph using the current context.
void beginFrame()
Specifies the start of a graphics frame.
void polishItems()
This function should be called as late as possible before sync().
bool sync()
This function is used to synchronize the QML scene with the rendering scene graph.
void invalidate()
Stop rendering and release resources.
static QQuickRenderTarget fromRhiRenderTarget(QRhiRenderTarget *renderTarget)
QQuickGraphicsConfiguration graphicsConfig
static QQuickWindowPrivate * get(QQuickWindow *c)
static void rhiCreationFailureMessage(const QString &backendName, QString *translatedMessage, QString *untranslatedMessage)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
The QResizeEvent class contains event parameters for resize events.
void setTexture(QRhiTexture *tex)
Sets the texture tex.
void setRenderBuffer(QRhiRenderBuffer *rb)
Sets the renderbuffer rb.
void setResolveTexture(QRhiTexture *tex)
Sets the resolve texture tex.
void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result)
Enqueues a texture-to-host copy operation as described by rb.
void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer)
Sets the renderBuffer for depth-stencil.
void setColorAttachments(std::initializer_list< QRhiColorAttachment > list)
Sets the list of color attachments.
FrameOpResult endOffscreenFrame(EndFrameFlags flags={})
Ends, submits, and waits for the offscreen frame.
bool makeThreadLocalNativeContextCurrent()
With OpenGL this makes the OpenGL context current on the current thread.
bool isYUpInFramebuffer() const
Implementation backend() const
FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags={})
Starts a new offscreen frame.
const char * backendName() const
@ MultisampleRenderBuffer
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
GraphicsApi
\value Unknown An unknown graphics API is in use \value Software The Qt Quick 2D Renderer is in use \...
static int chooseSampleCount(int samples, QRhi *rhi)
void setCurrentPaintDevice(QPaintDevice *device)
The QScreen class is used to query screen properties. \inmodule QtGui.
The QShowEvent class provides an event that is sent when a widget is shown.
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QWindow::Visibility visibility
void focusObjectChanged(QObject *object)
This signal is emitted when the final receiver of events tied to focus is changed to object.
void setTitle(const QString &)
void statusChanged(QDeclarativeComponent::Status status)
[1]
Combined button and popup list for selecting options.
@ ImInputItemClipRectangle
QTextStream & endl(QTextStream &stream)
Writes '\n' to the stream and flushes the stream.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
constexpr const T & qMax(const T &a, const T &b)
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLsizei GLsizei GLchar * source
GLuint GLenum GLenum transform
GLdouble GLdouble GLdouble GLdouble q
static qreal component(const QPointF &point, unsigned int i)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
#define Q_QUICK_INPUT_PROFILE(Type, DetailType, A, B)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define qPrintable(string)
QLatin1StringView QLatin1String
QWindow * qobject_cast< QWindow * >(QObject *o)
QUrl url("example.com")
[constructor-url-reference]
myObject disconnect()
[26]
app setAttribute(Qt::AA_DontShowIconsInMenus)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent