Add MenuSeparator

[ChangeLog][Controls] Added MenuSeparator to visually distinguish
between groups of items in a menu.

Change-Id: I7a52910b19633ed1188c90ca56c92346a28d4d5c
Task-number: QTBUG-54862
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
Mitch Curtis 2016-07-21 16:04:18 +02:00
parent 8874fddefc
commit 508bb6ddde
20 changed files with 615 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.6
import QtQuick.Templates 2.1 as T
T.MenuSeparator {
id: control
implicitWidth: Math.max(background ? background.implicitWidth : 0, contentItem.implicitWidth + leftPadding + rightPadding)
implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding)
padding: 2
topPadding: padding + 4
bottomPadding: padding + 4
//! [contentItem]
contentItem: Rectangle {
implicitWidth: 188
implicitHeight: 1
color: "#ccc"
}
//! [contentItem]
}

View File

@ -26,6 +26,7 @@ QML_CONTROLS = \
Label.qml \
Menu.qml \
MenuItem.qml \
MenuSeparator.qml \
Page.qml \
PageIndicator.qml \
Pane.qml \

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -0,0 +1,69 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
//! [file]
import QtQuick 2.6
import QtQuick.Controls 2.1
Item {
id: window
width: menu.contentItem.width
height: menu.contentItem.height
visible: true
// Indent it like this so that the indenting in the generated doc is normal.
Menu {
id: menu
contentItem.parent: window
MenuItem {
text: qsTr("New...")
}
MenuItem {
text: qsTr("Open...")
}
MenuItem {
text: qsTr("Save")
}
MenuSeparator {
padding: 0
topPadding: 12
bottomPadding: 12
contentItem: Rectangle {
implicitWidth: 200
implicitHeight: 1
color: "#1E000000"
}
}
MenuItem {
text: qsTr("Exit")
}
}
}
//! [file]

View File

@ -0,0 +1,60 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
//! [file]
import QtQuick 2.6
import QtQuick.Controls 2.1
Item {
id: window
width: menu.contentItem.width
height: menu.contentItem.height
visible: true
// Indent it like this so that the indenting in the generated doc is normal.
Menu {
id: menu
contentItem.parent: window
MenuItem {
text: qsTr("New...")
}
MenuItem {
text: qsTr("Open...")
}
MenuItem {
text: qsTr("Save")
}
MenuSeparator {}
MenuItem {
text: qsTr("Exit")
}
}
}
//! [file]

View File

@ -471,6 +471,23 @@
\l {Customizing Button}{Button}.
\section2 Customizing MenuSeparator
MenuSeparator consists of two visual items: \l {Control::background}{background}
and \l {Control::contentItem}{content item}.
\image qtquickcontrols2-menuseparator-custom.png
\quotefromfile qtquickcontrols2-menuseparator-custom.qml
\skipto import QtQuick 2.6
\printuntil import QtQuick.Controls 2.1
\skipto Menu
\printto contentItem.parent: window
\skipline contentItem.parent: window
\printuntil text: qsTr("Exit")
\printuntil }
\printuntil }
\section2 Customizing PageIndicator
PageIndicator consists of a \l {Control::background}{background}, \l {Control::contentItem}{content item}, and \l {PageIndicator::delegate}{delegate}.

View File

@ -39,6 +39,16 @@
sections offer guidelines for choosing the appropriate type of separator,
depending on the use case.
\section1 MenuSeparator Control
\image qtquickcontrols2-menuseparator.png
\l MenuSeparator should be used to separate items (typically MenuItem
controls) in a Menu. Grouping related menu items together makes it easier
for the user to interact with the menu. For example, a typical desktop
user interface might have \c Undo and \c Redo items in one group, and
\c Cut, \c Copy and \c Paste in another.
\section1 ToolSeparator Control
\image qtquickcontrols2-toolseparator.png

View File

@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.6
import QtQuick.Templates 2.1 as T
import QtQuick.Controls.Material 2.1
T.MenuSeparator {
id: control
implicitWidth: Math.max(background ? background.implicitWidth : 0, contentItem.implicitWidth + leftPadding + rightPadding)
implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding)
topPadding: 8
bottomPadding: 8
contentItem: Rectangle {
implicitWidth: 200
implicitHeight: 1
color: control.Material.dividerColor
}
}

View File

@ -32,6 +32,7 @@ QML_FILES += \
$$PWD/Label.qml \
$$PWD/Menu.qml \
$$PWD/MenuItem.qml \
$$PWD/MenuSeparator.qml \
$$PWD/Page.qml \
$$PWD/PageIndicator.qml \
$$PWD/Pane.qml \

View File

@ -141,6 +141,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickContainer,1>(uri, 2, 1, "Container");
qmlRegisterType(selector.select(QStringLiteral("Dialog.qml")), uri, 2, 1, "Dialog");
qmlRegisterType(selector.select(QStringLiteral("DialogButtonBox.qml")), uri, 2, 1, "DialogButtonBox");
qmlRegisterType(selector.select(QStringLiteral("MenuSeparator.qml")), uri, 2, 1, "MenuSeparator");
qmlRegisterType(selector.select(QStringLiteral("ToolSeparator.qml")), uri, 2, 1, "ToolSeparator");
}

View File

@ -0,0 +1,60 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.6
import QtQuick.Templates 2.1 as T
import QtQuick.Controls.Universal 2.1
T.MenuSeparator {
id: control
implicitWidth: Math.max(background ? background.implicitWidth : 0, contentItem.implicitWidth + leftPadding + rightPadding)
implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding)
padding: 12
topPadding: 9
bottomPadding: 10
contentItem: Rectangle {
implicitWidth: 188
implicitHeight: 1
color: control.Universal.baseMediumLowColor
}
background: Rectangle {
color: control.Universal.altMediumLowColor
}
}

View File

@ -16,6 +16,7 @@ QML_FILES += \
$$PWD/Label.qml \
$$PWD/Menu.qml \
$$PWD/MenuItem.qml \
$$PWD/MenuSeparator.qml \
$$PWD/Page.qml \
$$PWD/PageIndicator.qml \
$$PWD/Pane.qml \

View File

@ -56,6 +56,7 @@
#include <QtQuickTemplates2/private/qquicklabel_p.h>
#include <QtQuickTemplates2/private/qquickmenu_p.h>
#include <QtQuickTemplates2/private/qquickmenuitem_p.h>
#include <QtQuickTemplates2/private/qquickmenuseparator_p.h>
#include <QtQuickTemplates2/private/qquickoverlay_p.h>
#include <QtQuickTemplates2/private/qquickpage_p.h>
#include <QtQuickTemplates2/private/qquickpageindicator_p.h>
@ -181,6 +182,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickDialog>(uri, 2, 1, "Dialog");
qmlRegisterType<QQuickDialogButtonBox>(uri, 2, 1, "DialogButtonBox");
qmlRegisterType<QQuickDialogButtonBoxAttached>();
qmlRegisterType<QQuickMenuSeparator>(uri, 2, 1, "MenuSeparator");
qmlRegisterType<QQuickPopup, 1>(uri, 2, 1, "Popup");
qmlRegisterType<QQuickRangeSlider, 1>(uri, 2, 1, "RangeSlider");
qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider");

View File

@ -0,0 +1,80 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qquickmenuseparator_p.h"
QT_BEGIN_NAMESPACE
/*!
\qmltype MenuSeparator
\inherits Control
\instantiates QQuickMenuSeparator
\inqmlmodule QtQuick.Controls
\since 5.8
\ingroup qtquickcontrols2-separators
\brief Separates a group of items in a menu from adjacent items.
MenuSeparator is used to visually distinguish between groups of items in a
menu by separating them with a line.
\image qtquickcontrols2-menuseparator.png
\quotefromfile qtquickcontrols2-menuseparator-custom.qml
\skipto import QtQuick 2.6
\printuntil import QtQuick.Controls 2.1
\skipto Menu
\printto contentItem.parent: window
\skipline contentItem.parent: window
\printuntil text: qsTr("Exit")
\printuntil }
\printuntil }
\sa {Customizing MenuSeparator}, {Separator Controls}
*/
QQuickMenuSeparator::QQuickMenuSeparator(QQuickItem *parent) :
QQuickControl(parent)
{
}
#ifndef QT_NO_ACCESSIBILITY
QAccessible::Role QQuickMenuSeparator::accessibleRole() const
{
return QAccessible::Separator;
}
#endif
QT_END_NAMESPACE

View File

@ -0,0 +1,75 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQUICKMENUSEPARATOR_P_H
#define QQUICKMENUSEPARATOR_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtQuickTemplates2/private/qquickcontrol_p.h>
QT_BEGIN_NAMESPACE
class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuSeparator : public QQuickControl
{
Q_OBJECT
public:
explicit QQuickMenuSeparator(QQuickItem *parent = nullptr);
protected:
#ifndef QT_NO_ACCESSIBILITY
QAccessible::Role accessibleRole() const override;
#endif
private:
Q_DISABLE_COPY(QQuickMenuSeparator)
};
QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickMenuSeparator)
#endif // QQUICKMENUSEPARATOR_P_H

View File

@ -30,6 +30,7 @@ HEADERS += \
$$PWD/qquickmenu_p.h \
$$PWD/qquickmenu_p_p.h \
$$PWD/qquickmenuitem_p.h \
$$PWD/qquickmenuseparator_p.h \
$$PWD/qquickoverlay_p.h \
$$PWD/qquickpage_p.h \
$$PWD/qquickpageindicator_p.h \
@ -88,6 +89,7 @@ SOURCES += \
$$PWD/qquicklabel.cpp \
$$PWD/qquickmenu.cpp \
$$PWD/qquickmenuitem.cpp \
$$PWD/qquickmenuseparator.cpp \
$$PWD/qquickoverlay.cpp \
$$PWD/qquickpage.cpp \
$$PWD/qquickpageindicator.cpp \

View File

@ -0,0 +1,73 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.6
import QtQuick.Controls 2.1
ApplicationWindow {
width: 200
height: 200
property alias menu: menu
MenuItem {
id: newMenuItem
text: qsTr("New")
}
MenuSeparator {
id: menuSeparator
}
MenuItem {
id: saveMenuItem
text: qsTr("Save")
}
Menu {
id: menu
Component.onCompleted: {
addItem(newMenuItem)
addItem(menuSeparator)
addItem(saveMenuItem)
}
}
}

View File

@ -50,6 +50,7 @@
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickTemplates2/private/qquickmenu_p.h>
#include <QtQuickTemplates2/private/qquickmenuitem_p.h>
#include <QtQuickTemplates2/private/qquickmenuseparator_p.h>
using namespace QQuickVisualTestUtil;
@ -65,6 +66,7 @@ private slots:
void contextMenuKeyboard();
void menuButton();
void addItem();
void menuSeparator();
};
void tst_menu::defaults()
@ -272,6 +274,49 @@ void tst_menu::addItem()
QTRY_VERIFY(!menu->isVisible());
}
void tst_menu::menuSeparator()
{
QQuickApplicationHelper helper(this, QLatin1String("menuSeparator.qml"));
QQuickApplicationWindow *window = helper.window;
window->show();
QVERIFY(QTest::qWaitForWindowActive(window));
QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
QVERIFY(menu);
menu->open();
QVERIFY(menu->isVisible());
QQuickMenuItem *newMenuItem = qobject_cast<QQuickMenuItem*>(menu->itemAt(0));
QVERIFY(newMenuItem);
QCOMPARE(newMenuItem->text(), QStringLiteral("New"));
QQuickMenuSeparator *menuSeparator = qobject_cast<QQuickMenuSeparator*>(menu->itemAt(1));
QVERIFY(menuSeparator);
QQuickMenuItem *saveMenuItem = qobject_cast<QQuickMenuItem*>(menu->itemAt(2));
QVERIFY(saveMenuItem);
QCOMPARE(saveMenuItem->text(), QStringLiteral("Save"));
QTRY_VERIFY(!QQuickItemPrivate::get(saveMenuItem)->culled); // QTBUG-53262
// Clicking on items should still close the menu.
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
newMenuItem->mapToScene(QPointF(newMenuItem->width() / 2, newMenuItem->height() / 2)).toPoint());
QTRY_VERIFY(!menu->isVisible());
menu->open();
QVERIFY(menu->isVisible());
// Clicking on a separator shouldn't close the menu.
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
menuSeparator->mapToScene(QPointF(menuSeparator->width() / 2, menuSeparator->height() / 2)).toPoint());
QVERIFY(menu->isVisible());
// Clicking on items should still close the menu.
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
saveMenuItem->mapToScene(QPointF(saveMenuItem->width() / 2, saveMenuItem->height() / 2)).toPoint());
QTRY_VERIFY(!menu->isVisible());
}
QTEST_MAIN(tst_menu)
#include "tst_menu.moc"

View File

@ -97,6 +97,12 @@ ApplicationWindow {
text: "Option 3"
checkable: true
}
MenuSeparator {}
MenuItem {
text: "Option A"
}
}
}
ToolButton {