diff --git a/examples/quick/controls/gallery/content/Controls.qml b/examples/quick/controls/gallery/content/Controls.qml index abcebbebcb7a9b13f2075ae8d34ed6263998c14a..93b933d780b5713f22eba950ba36381aa1b82293 100644 --- a/examples/quick/controls/gallery/content/Controls.qml +++ b/examples/quick/controls/gallery/content/Controls.qml @@ -66,13 +66,18 @@ Item { Button { id: button1 text: "Button 1" - width: 97 + width: 92 tooltip:"This is an interesting tool tip" } Button { id:button2 text:"Button 2" - width:97 + width: 102 + menu: Menu { + MenuItem { text: "This Button" } + MenuItem { text: "Happens To Have" } + MenuItem { text: "A Menu Assigned" } + } } } ComboBox { diff --git a/src/controls/Button.qml b/src/controls/Button.qml index ff84aecd56259fa07926768f37713cfe7eeb4e84..ccf1973bdf87f4b8fc4763761d88540339ebae97 100644 --- a/src/controls/Button.qml +++ b/src/controls/Button.qml @@ -83,9 +83,46 @@ BasicButton { */ property url iconSource + /*! Assign a \l Menu to this property to get a pull-down menu button. + + The default value is \c null. + */ + property Menu menu: null + activeFocusOnTab: true Accessible.name: text style: Qt.createComponent(Settings.theme() + "/ButtonStyle.qml", button) + + readonly property bool pressed: __behavior.effectivePressed || menu && menu.__popupVisible + + Binding { + target: menu + property: "__minimumWidth" + value: button.__panel.width + } + + Binding { + target: menu + property: "__visualItem" + value: button + } + + Connections { + target: __behavior + onEffectivePressedChanged: { + if (__behavior.effectivePressed && menu) + popupMenuTimer.start() + } + } + + Timer { + id: popupMenuTimer + interval: 10 + onTriggered: { + __behavior.keyPressed = false + menu.__popup(0, button.height, 0) + } + } } diff --git a/src/private/BasicButton.qml b/src/private/BasicButton.qml index 759a9f902e0042bb337d3e0e2d0f22534f5e8ac3..f3ab59736dfb7f4b72ca5b1000a94b5ce62670d3 100644 --- a/src/private/BasicButton.qml +++ b/src/private/BasicButton.qml @@ -59,7 +59,7 @@ Control { /*! \qmlproperty bool BasicButton::pressed This property holds whether the button is pressed. */ - property alias pressed: behavior.effectivePressed + readonly property bool pressed: behavior.effectivePressed /*! This property holds whether the button is checkable. @@ -166,6 +166,9 @@ Control { } } + /*! \internal */ + property var __behavior: behavior + SystemPalette { id: syspal } states: [ diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp index b54f386951790e0e1643d2f38193f19bb2d3dac2..548e8104d0ae376f73315f7bedcd7812df085f4d 100644 --- a/src/private/qquickstyleitem.cpp +++ b/src/private/qquickstyleitem.cpp @@ -199,6 +199,25 @@ void QQuickStyleItem::initStyleOption() const QFont *font = QGuiApplicationPrivate::platformTheme()->font(platformFont); if (font) opt->fontMetrics = QFontMetrics(*font); + if (QObject * menu = m_properties["menu"].value<QObject *>()) { + opt->features |= QStyleOptionButton::HasMenu; +#ifdef Q_OS_MAC + if (style() == "mac") { + if (platformFont == QPlatformTheme::PushButtonFont) + menu->setProperty("__xOffset", 12); + else + menu->setProperty("__xOffset", 11); + if (platformFont == QPlatformTheme::MiniFont) + menu->setProperty("__yOffset", 5); + else if (platformFont == QPlatformTheme::SmallFont) + menu->setProperty("__yOffset", 6); + else + menu->setProperty("__yOffset", 3); + if (font) + menu->setProperty("__font", *font); + } +#endif + } } break; case ItemRow: { diff --git a/src/styles/Desktop/ButtonStyle.qml b/src/styles/Desktop/ButtonStyle.qml index b8f5c189bf58869c12bb832ba7b547fa5c6af70b..3ae42c03e95e9db8b338bc922d2c79cda6cc5880 100644 --- a/src/styles/Desktop/ButtonStyle.qml +++ b/src/styles/Desktop/ButtonStyle.qml @@ -54,7 +54,8 @@ Style { activeControl: control.isDefault ? "default" : "f" properties: { - "icon": control.__action.__icon + "icon": control.__action.__icon, + "menu": control.menu } } }