aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRami Potinkara <rami.potinkara@qt.io>2025-08-26 10:05:04 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-09-11 18:27:22 +0000
commitc670b70527b3da5b42f4d25c314bab2738c81f4b (patch)
treebd40d8bded08ea79f394a6db22d347fd7bb4fa57
parent18f942b22fbd840b66e16cb9214a49f53ac82413 (diff)
Android: append Qt Quick for Android fragments documentation
This patch - fixes small syntax error - adds the link to Qt Academy course - add alternative way to initialize layout parameters Task-number: QTBUG-139320 Pick-to: 6.8 Change-Id: I981f097474fdbc410df30076098b71f08c070a1f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 94cb18f73c7d279d3d8bd31f07e727d12ff6e49e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 7bd4e53f16f38d83f8d0db4bb86c71d32692862f)
-rw-r--r--src/qml/doc/src/external-resources.qdoc13
-rw-r--r--src/quick/doc/src/android/qtquick-for-android-fragments.qdoc78
2 files changed, 62 insertions, 29 deletions
diff --git a/src/qml/doc/src/external-resources.qdoc b/src/qml/doc/src/external-resources.qdoc
index 90dc986e23..60eebb16ab 100644
--- a/src/qml/doc/src/external-resources.qdoc
+++ b/src/qml/doc/src/external-resources.qdoc
@@ -85,3 +85,16 @@
\externalpage https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/
\title Kotlin: String
*/
+/*!
+ \externalpage https://developer.android.com/reference/android/view/View#event-handling-and-threading
+ \title Android: Event Handling and Threading
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/widget/FrameLayout
+ \title Android: FrameLayout
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams
+ \title Android: FrameLayout.LayoutParams
+*/
+
diff --git a/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc b/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc
index 79dd6fcf19..0b742ae5e3 100644
--- a/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc
+++ b/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc
@@ -8,17 +8,17 @@
\ingroup qq4a-extra-topics
You can have a \l QtQuickView in an Android UI layout by using a ViewGroup-based
- object. Here we'll use a
- \l{https://developer.android.com/reference/android/widget/FrameLayout}{FrameLayout}.
+ object. Here we'll use a \l{Android: FrameLayout}{FrameLayout}.
If you're not familiar with the \l QtQuickView API, read its documentation
before continuing with this tutorial.
+ Before proceeding, it's worthwhile to explore the Qt Academy course,
+ \l{Qt Academy: Embed 3D in an Android}{Embedding Qt Quick 3D Content in an Android App}.
+
To start, create a new project in Android Studio using the
\uicontrol{Bottom Navigation Views Activity} template.
- //!TODO add Qt Academy Link here when the course is published.
-
\list 1
\li Locate the Fragment or Activity under which you want your QtQuickView
to be visible. Here we use \c HomeFragment and \c fragment_home.xml.
@@ -57,31 +57,51 @@
private lateinit var homeQtQuickView: QtQuickView
\endcode
- \li Inside the overloaded \c onCreateView() function:
- \list 1
- \li Assign your QtQuickView, giving it the Activity context using \c this.Activity
- \code
- homeQtQuickView = QtQuickView(this.activity)
- homeQmlContent = Screen01()
- \endcode
- \li Initialize the layout parameters with
- \l {https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams}{FrameLayout.LayoutParams}
- \code
- val params = FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
-
- binding = FragmentHomeBinding.inflate(inflater, container, false)
- val root: View = binding.root
- \li Add it to the layout:
- \code
- binding.homeQmlFrame.addView(homeQtQuickView, params)
- \endcode
- \li Load your QML content:
- \code
- homeQtQuickView.loadContent(homeQmlContent)
- return root
- \endcode
- \endlist
+ \li Assign your QtQuickView, giving it the Activity instance
+ using \c requireActivity()
+ \code
+ homeQtQuickView = QtQuickView(requireActivity())
+ homeQmlContent = Screen01()
+ \endcode
+
+ \li Initialize the layout parameters, if you create views
+ programmatically, add views dynamically or change them on runtime.
+ Otherwise you may skip this section and you do not need to use
+ \c params with \c addView().
+ \code
+ val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT)
+ \endcode
+
+ \li Add your view to the layout, either with:
+ \list 1
+ \li Using \l{Android: View binding}{View binding} inside \c onCreateView():
+ First check that view binding is enabled by adding \c buildFeature
+ section into build.gradle.kts android section of your app:
+ \code
+ buildFeatures {
+ viewBinding = true
+ }
+ \endcode
+ Then add the following in \c onCreateView():
+ \code
+ binding = FragmentHomeBinding.inflate( inflater, container, false)
+ homeQtQuickView.loadContent(homeQmlContent)
+
+ val root: View = binding.root
+ binding.homeQmlFrame.addView(homeQtQuickView, params)
+ ...
+ return root
+ \endcode
+ \li Using \c {findViewById()} inside \c onCreate():
+ \code
+ val qtFrame = findViewById(R.id.qtFrame)
+ qmlFrame.addView(m_quickView, params)
+ m_quickView.loadContent(homeQmlContent)
+ \endcode
+ See usage from other
+ \l {Qt Quick for Android Studio Projects}{Qt Quick for Android examples}.
+ \endlist
\endlist
Your Qt Quick content will now appear in your home fragment.
*/