在 QML 主窗口按下的按钮上打开 qt 小部件窗口

时间:2021-06-14 16:34:38

标签: qt

我有两个应用程序,一个完全在 c++ qt 小部件中,另一个 qml 用于某些动画和不同的菜单类型。 目前这是两个不同的项目,我想将 c++ 应用程序与我的 qml 合并,其中主窗口是 qml 类型,它将替换小部件的主窗口,单击 qml 窗口中的按钮将带我到 c++ 应用程序窗口,它执行其他功能。 我不确定如何将 main.qml 与小部件类相结合。 什么类型的窗口应该是一个 qdialog/qwidget/mainwindow? 如何从 qml 显示 qt 小部件窗口?

这是一段qml代码

import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import QtQuick.Extras 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 1.4
Window {
    id: window
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")


    Rectangle {
        id: rectangle
        x: 376
        y: 156
        width: 252
        height: 216
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.verticalCenterOffset: 6
        anchors.rightMargin: 12
        color: "transparent"

        PieMenu{
            id: mypie
            x: 66
            y: 14
            width: 200
            height: 200
            rotation: -90
            anchors.right:parent.right
            anchors.rightMargin: 0
            MenuItem{
                text: "Create Scenario"
                onTriggered: {
                              **"MUST OPEN A qt widget window"** 
            }
            MenuItem{
                ///////
            }

            MenuItem{
            ///////////////////////////////}

            MenuItem{
                /////////
            }
            style:  PieMenuStyle {
                shadowRadius: 0

                menuItem: Item {
                    id: item
                    rotation: -90 + sectionCenterAngle(styleData.index)

                    Rectangle {
                        width: parent.height * 0.2
                        height: width
                        color: "#049dac"
                        radius: width / 2
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter

                        Text {
                            id: textItem
                        //    text: control.menuItems[styleData.index].text
                            anchors.centerIn: parent
                            color: control.currentIndex === styleData.index ? "red" : "white"
                            rotation: -item.rotation
                        }
                    }
                }
            }
        }

        RoundButton {
            id: roundButton
            x: 218
            y: 94
            text: "+"
            background: Rectangle {
                       radius: myRoundButton.radius
                       color: "#049dac"
                   }

            MouseArea{
                id:forhover
                anchors.fill: parent
                hoverEnabled: true
            }

            onHoveredChanged: {
                if(!(mypie.visible) === true)
                    mypie.visible=true
                if(mypie.visible === false )
                    mypie.visible = false
            }

        }
    }
}

0 个答案:

没有答案
相关问题