aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNicholas Bennett <nicholas.bennett@qt.io>2025-06-19 14:23:47 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-06-26 12:18:18 +0000
commit1eb1480bb1ca6baf3edbc0c75a40805b8dbc42f9 (patch)
tree9bc60a8916f4de493fd4dc0e2a7ba300e8b8fe71 /src
parent95e159734d090606ce28f080dcfbe0900383f719 (diff)
Docs: Add tutorial on using QtQuickViews in Android Fragments
-Added a tutorial page. -Added autogenerated table of topics at the bottom of Qt Quick For Android -page, added qq4a-extra-topics group name for this purpose. -Updated the Qt Quick For Android Class doc to mention the fragments tutorial. Task-number: QTBUG-137077 Pick-to: 6.8 Change-Id: Ia7470c90fae385fd38170b2786995a6816b97b10 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> (cherry picked from commit 691dab42c34337e1c9eec5a2efd07faefed9631a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 58274b72c0b021cfbf5429f371ee4c97788ad5ff)
Diffstat (limited to 'src')
-rw-r--r--src/quick/doc/src/android/qtquick-for-android-fragments.qdoc87
-rw-r--r--src/quick/doc/src/android/qtquick-for-android.qdoc6
-rw-r--r--src/quick/platform/android/jar/src/org/qtproject/qt/android/QtQuickView.qdoc4
3 files changed, 97 insertions, 0 deletions
diff --git a/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc b/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc
new file mode 100644
index 0000000000..79dd6fcf19
--- /dev/null
+++ b/src/quick/doc/src/android/qtquick-for-android-fragments.qdoc
@@ -0,0 +1,87 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \title Android Fragments with Qt Quick for Android
+ \brief Tutorial on using Qt Quick Views in Android Fragments
+ \page qtquick-for-android-fragments.html
+ \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}.
+
+ If you're not familiar with the \l QtQuickView API, read its documentation
+ before continuing with this tutorial.
+
+ 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.
+
+ \li In \c fragment_home.xml create a FrameLayout and set its \c id as
+ shown below.
+ \code
+ <FrameLayout
+ android:id="@+id/homeQmlFrame"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHeight_percent="0.8"/>
+ \endcode
+ Note this id, as it needed to be referred to in \c HomeFragment when
+ binding the layout.
+
+ \li Inside HomeFragment.kt, add an import statement for FrameLayout:
+ \code
+ import android.widget.FrameLayout
+ \endcode
+
+ \li Add your imports for your \l QtQuickView and Screen01 QML type
+ and declare them inside the class:
+
+ \code
+ import org.qtproject.qt.android.QtQuickView
+ import org.qtproject.example.RoboApp.RoboContent.Screen01
+
+ class HomeFragment : Fragment() {
+
+ private var binding: FragmentHomeBinding? = null
+ private lateinit var homeQmlContent: Screen01
+ 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
+ \endlist
+ Your Qt Quick content will now appear in your home fragment.
+*/
diff --git a/src/quick/doc/src/android/qtquick-for-android.qdoc b/src/quick/doc/src/android/qtquick-for-android.qdoc
index 34350c9c11..5a2ac59b68 100644
--- a/src/quick/doc/src/android/qtquick-for-android.qdoc
+++ b/src/quick/doc/src/android/qtquick-for-android.qdoc
@@ -93,4 +93,10 @@
of your build toolchain. \QtTAS uses the plugin to build your projects in
Android Studio.
+ \section1 Where to go from here
+
+ The following additional topics apply to Qt Quick For Android:
+
+ \annotatedlist qq4a-extra-topics
+
*/
diff --git a/src/quick/platform/android/jar/src/org/qtproject/qt/android/QtQuickView.qdoc b/src/quick/platform/android/jar/src/org/qtproject/qt/android/QtQuickView.qdoc
index adcbeea917..d5e1c2a1a9 100644
--- a/src/quick/platform/android/jar/src/org/qtproject/qt/android/QtQuickView.qdoc
+++ b/src/quick/platform/android/jar/src/org/qtproject/qt/android/QtQuickView.qdoc
@@ -86,6 +86,10 @@
For a more detailed example, see \l {Qt Quick for Android Studio Projects}.
+ \section1 QtQuickViews can be used in Android Fragments
+
+ See the \l{Android Fragments and Qt Quick for Android} tutorial for how to do this.
+
\section1 Known issues
Here are the known issues with this API. They may be resolved and removed in a patch