diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-11-29 13:21:38 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2015-01-20 16:15:45 +0100 |
commit | fc8adfea9f5e09e5f47ac4e592e5d9db471caede (patch) | |
tree | 0a4a83bd384498fefa688f166b655fe95996bf7b /src/widgets | |
parent | 463c559962ad480c69fdbe6ebcf741a4b2bd6eee (diff) |
Introduce helper for QML to allow creating QWidget hierarchies
Commit 1259c5768e410361bcd8b5cf0c2057a2ebabda83 in qtdeclarative removed the
ability to create QWidgets in QML by giving them the correct parent, which
requires calling QWidget::setParent instead of QObject::setParent. This patch
introduces a hook that will allow QtQml to give widgets a proper parent.
Change-Id: I84c57ca5032582c43e405219343d55ac9cf2ffa0
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 8 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index bf05b2029b..392db60e2b 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -630,6 +630,9 @@ void QApplicationPrivate::initialize() // needed for a static build. qRegisterWidgetsVariant(); + // needed for widgets in QML + QAbstractDeclarativeData::setWidgetParent = QWidgetPrivate::setWidgetParentHelper; + if (application_type != QApplicationPrivate::Tty) (void) QApplication::style(); // trigger creation of application style #ifndef QT_NO_STATEMACHINE diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7b7600fdc3..403e64d1ba 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12779,6 +12779,14 @@ void QWidget::clearMask() setMask(QRegion()); } +void QWidgetPrivate::setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent) +{ + Q_ASSERT(widgetAsObject->isWidgetType()); + Q_ASSERT(!newParent || newParent->isWidgetType()); + QWidget *widget = static_cast<QWidget*>(widgetAsObject); + widget->setParent(static_cast<QWidget*>(newParent)); +} + QT_END_NAMESPACE #include "moc_qwidget.cpp" diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 50a8066a41..afc2cfc06b 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -653,6 +653,8 @@ public: virtual void resolveSamples() { } #endif + static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent); + // Variables. // Regular pointers (keep them together to avoid gaps on 64 bit architectures). QWExtra *extra; |