可拖动对象上的QML pieMenu

时间:2018-02-24 14:06:59

标签: qt qml

我有一个由Javascript创建的可拖动对象,它工作正常。但是当我在其中创建PieMenu时,该对象不会在Javascript上下文中创建/可见:

import QtQuick 2.8
import QtQuick.Controls.Styles 1.4
import QtQuick.Extras 1.4
import QtQml.Models 2.2


Rectangle {
        id: rev
        width: 100
        height: 80
        color: "transparent"
        antialiasing: false
        Drag.active: dragArea.drag.active

        MouseArea {
                  id: dragArea
                  width: parent.width
                  height: parent.height + 10 // easier to get
                  anchors.centerIn: parent
                  drag.target: parent
                  drag.axis: Drag.XAndYAxis
                  onClicked: pieMenu.popup(mouseX, mouseY), console.log("clicked")
                }

        PieMenu {
            id: pieMenu

            MenuItem {
                text: "Add vertical bar"
                onTriggered: print("Action 2")
            }   
        }



        Gauge {
            id: revgauge
            anchors.fill: parent
            anchors.margins: 10
            orientation : Qt.Horizontal
            minorTickmarkCount: 4
            tickmarkStepSize : 5000
            minimumValue: 0
            maximumValue: 10000
            Behavior on value {
                NumberAnimation {
                    duration: 5
                }
            }
            Text {                    
                font.pixelSize: (parent.height / 3)
                anchors.top : parent.top
                font.bold: true
                font.family: "Eurostile"
                color: "white"
                anchors.horizontalCenter: parent.horizontalCenter
            }
              style: GaugeStyle {
                valueBar: Rectangle {
                   implicitWidth:  rev.height /3
                    color: Qt.rgba(revgauge.value / revgauge.maximumValue, 0, 1 - revgauge.value / revgauge.maximumValue, 1)
                }
            }
      }
}

Mousearea可以同时处理拖动和PieMenu吗?如果没有,怎么解决?

1 个答案:

答案 0 :(得分:0)

考虑QML super().actions boundingItem。它解决了您提交的PieMenu的确切问题。