aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickmenu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickmenu.cpp')
-rw-r--r--src/quicktemplates2/qquickmenu.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp
index 91372777..0043dddd 100644
--- a/src/quicktemplates2/qquickmenu.cpp
+++ b/src/quicktemplates2/qquickmenu.cpp
@@ -68,7 +68,7 @@ static const int SUBMENU_DELAY = 225;
/*!
\qmltype Menu
\inherits Popup
- \instantiates QQuickMenu
+//! \instantiates QQuickMenu
\inqmlmodule QtQuick.Controls
\since 5.7
\ingroup qtquickcontrols2-menus
@@ -170,6 +170,14 @@ static const int SUBMENU_DELAY = 225;
Although \l {MenuItem}{MenuItems} are most commonly used with Menu, it can
contain any type of item.
+ \section1 Margins
+
+ As it is inherited from Popup, Menu supports \l {Popup::}{margins}. By
+ default, all of the built-in styles specify \c 0 for Menu's margins to
+ ensure that the menu is kept within the bounds of the window. To allow a
+ menu to go outside of the window (to animate it moving into view, for
+ example), set the margins property to \c -1.
+
\sa {Customizing Menu}, MenuItem, {Menu Controls}, {Popup Controls}
*/
@@ -178,8 +186,9 @@ static const int SUBMENU_DELAY = 225;
This property holds whether the popup wants focus.
- When the popup actually receives focus, \l activeFocus will be \c true.
- For more information, see \l {Keyboard Focus in Qt Quick}.
+ When the popup actually receives focus, \l{Popup::}{activeFocus}
+ will be \c true. For more information, see
+ \l {Keyboard Focus in Qt Quick}.
The default value is \c false.
@@ -207,8 +216,12 @@ public:
QQuickMenuPrivate::QQuickMenuPrivate()
{
- Q_Q(QQuickMenu);
cascade = shouldCascade();
+}
+
+void QQuickMenuPrivate::init()
+{
+ Q_Q(QQuickMenu);
contentModel = new QQmlObjectModel(q);
}
@@ -282,8 +295,8 @@ QQuickItem *QQuickMenuPrivate::beginCreateItem()
QQuickItem *item = qobject_cast<QQuickItem *>(object);
if (!item)
delete object;
-
- QQml_setParent_noEvent(item, q);
+ else
+ QQml_setParent_noEvent(item, q);
return item;
}
@@ -712,9 +725,20 @@ QQuickMenu::QQuickMenu(QObject *parent)
{
Q_D(QQuickMenu);
setFocus(true);
+ d->init();
connect(d->contentModel, &QQmlObjectModel::countChanged, this, &QQuickMenu::countChanged);
}
+QQuickMenu::~QQuickMenu()
+{
+ Q_D(QQuickMenu);
+ // We have to do this to ensure that the change listeners are removed.
+ // It's too late to do this in ~QQuickMenuPrivate, as contentModel has already
+ // been destroyed before that is called.
+ while (d->contentModel->count() > 0)
+ d->removeItem(0, d->itemAt(0));
+}
+
/*!
\qmlmethod Item QtQuick.Controls::Menu::itemAt(int index)