创建简单的入门菜单QTQICK/QML

发布于 2025-02-01 01:06:46 字数 837 浏览 1 评论 0原文

我想用简单的动画创建qml中的按钮菜单 “ nofollow noreferrer”> simple qml

菜单

编辑:我也添加了此代码,但是每当我单击任何按钮时,菜单都会消失

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Menu {
           id: menu
            visible: true

           MenuItem {
              Button{
                  text:"Play"
              }
           }
           MenuItem {
               Button{
                   text:"Play"
               }
           }
           MenuItem {
               Button{
                   text:"Sett"
               }
           }
       }



}

I want to create menu of buttons in QML with simple animation
Simple QML Menu

When I add a button after another I only get the last one

Edit: I added this code also but everytime I click any button the menu disappears

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Menu {
           id: menu
            visible: true

           MenuItem {
              Button{
                  text:"Play"
              }
           }
           MenuItem {
               Button{
                   text:"Play"
               }
           }
           MenuItem {
               Button{
                   text:"Sett"
               }
           }
       }



}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2025-02-08 01:06:46

a menuitem 指的是添加一个按钮小时候的按钮。

文档显示了许多简单的示例,例如:

    Menu {
        id: menu

        MenuItem {
            text: "New..."
            onTriggered: document.reset()
        }
        MenuItem {
            text: "Open..."
            onTriggered: openDialog.open()
        }
        MenuItem {
            text: "Save"
            onTriggered: saveDialog.open()
        }
    }

A MenuItem already derives from AbstractButton, so there's no point in adding a Button as a child of the MenuItem.

The docs show many simple examples, like this:

    Menu {
        id: menu

        MenuItem {
            text: "New..."
            onTriggered: document.reset()
        }
        MenuItem {
            text: "Open..."
            onTriggered: openDialog.open()
        }
        MenuItem {
            text: "Save"
            onTriggered: saveDialog.open()
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文