diff options
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 083b7dbae1..35cf06927a 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -107,6 +107,7 @@ void QQuickWidgetPrivate::init(QQmlEngine* e) renderControl = new QQuickWidgetRenderControl(q); offscreenWindow = new QQuickWindow(*new QQuickOffcreenWindowPrivate(),renderControl); offscreenWindow->setTitle(QString::fromLatin1("Offscreen")); + offscreenWindow->setObjectName(QString::fromLatin1("QQuickOffScreenWindow")); // Do not call create() on offscreenWindow. // Check if the Software Adaptation is being used @@ -525,7 +526,7 @@ QImage QQuickWidgetPrivate::grabFramebuffer() */ QQuickWidget::QQuickWidget(QWidget *parent) -: QWidget(*(new QQuickWidgetPrivate), parent, nullptr) + : QWidget(*(new QQuickWidgetPrivate), parent, {}) { setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); @@ -553,7 +554,7 @@ QQuickWidget::QQuickWidget(const QUrl &source, QWidget *parent) \sa Status, status(), errors() */ QQuickWidget::QQuickWidget(QQmlEngine* engine, QWidget *parent) - : QWidget(*(new QQuickWidgetPrivate), parent, nullptr) + : QWidget(*(new QQuickWidgetPrivate), parent, {}) { setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); @@ -802,15 +803,29 @@ void QQuickWidgetPrivate::updateSize() q->updateGeometry(); } } else if (resizeMode == QQuickWidget::SizeRootObjectToView) { - bool needToUpdateWidth = !qFuzzyCompare(q->width(), root->width()); - bool needToUpdateHeight = !qFuzzyCompare(q->height(), root->height()); - - if (needToUpdateWidth && needToUpdateHeight) - root->setSize(QSizeF(q->width(), q->height())); - else if (needToUpdateWidth) - root->setWidth(q->width()); - else if (needToUpdateHeight) - root->setHeight(q->height()); + const bool needToUpdateWidth = !qFuzzyCompare(q->width(), root->width()); + const bool needToUpdateHeight = !qFuzzyCompare(q->height(), root->height()); + + if (needToUpdateWidth && needToUpdateHeight) { + // Make sure that we have realistic sizing behavior by following + // what on-screen windows would do and resize everything, not just + // the root item. We do this because other types may be relying on + // us to behave correctly. + const QSizeF newSize(q->width(), q->height()); + offscreenWindow->resize(newSize.toSize()); + offscreenWindow->contentItem()->setSize(newSize); + root->setSize(newSize); + } else if (needToUpdateWidth) { + const int newWidth = q->width(); + offscreenWindow->setWidth(newWidth); + offscreenWindow->contentItem()->setWidth(newWidth); + root->setWidth(newWidth); + } else if (needToUpdateHeight) { + const int newHeight = q->height(); + offscreenWindow->setHeight(newHeight); + offscreenWindow->contentItem()->setHeight(newHeight); + root->setHeight(newHeight); + } } } @@ -848,13 +863,13 @@ QSize QQuickWidgetPrivate::rootObjectSize() const return rootObjectSize; } -void QQuickWidgetPrivate::handleContextCreationFailure(const QSurfaceFormat &format, bool isEs) +void QQuickWidgetPrivate::handleContextCreationFailure(const QSurfaceFormat &format) { Q_Q(QQuickWidget); QString translatedMessage; QString untranslatedMessage; - QQuickWindowPrivate::contextCreationFailureMessage(format, &translatedMessage, &untranslatedMessage, isEs); + QQuickWindowPrivate::contextCreationFailureMessage(format, &translatedMessage, &untranslatedMessage); static const QMetaMethod errorSignal = QMetaMethod::fromSignal(&QQuickWidget::sceneGraphError); const bool signalConnected = q->isSignalConnected(errorSignal); @@ -896,10 +911,9 @@ void QQuickWidgetPrivate::createContext() context->setScreen(shareContext->screen()); } if (!context->create()) { - const bool isEs = context->isOpenGLES(); delete context; context = nullptr; - handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs); + handleContextCreationFailure(offscreenWindow->requestedFormat()); return; } @@ -1096,14 +1110,14 @@ void QQuickWidgetPrivate::setRootObject(QObject *obj) root = sgItem; sgItem->setParentItem(offscreenWindow->contentItem()); } else if (qobject_cast<QWindow *>(obj)) { - qWarning() << "QQuickWidget does not support using windows as a root item." << endl - << endl - << "If you wish to create your root window from QML, consider using QQmlApplicationEngine instead." << endl; + qWarning() << "QQuickWidget does not support using windows as a root item." << Qt::endl + << Qt::endl + << "If you wish to create your root window from QML, consider using QQmlApplicationEngine instead." << Qt::endl; } else { - qWarning() << "QQuickWidget only supports loading of root objects that derive from QQuickItem." << endl - << endl - << "Ensure your QML code is written for QtQuick 2, and uses a root that is or" << endl - << "inherits from QtQuick's Item (not a Timer, QtObject, etc)." << endl; + qWarning() << "QQuickWidget only supports loading of root objects that derive from QQuickItem." << Qt::endl + << Qt::endl + << "Ensure your QML code is written for QtQuick 2, and uses a root that is or" << Qt::endl + << "inherits from QtQuick's Item (not a Timer, QtObject, etc)." << Qt::endl; delete obj; root = nullptr; } |