QML工具栏菜单位置不正确

时间:2017-06-22 06:45:21

标签: qt qml qtquick2 qtquickcontrols

我试图修改Cura桌面应用程序。有一个工具栏用于旋转/移动对象。

在默认的Cura应用程序中,它位于屏幕的左侧。我已将其更改为屏幕底部,但由于这个原因,当我单击工具栏按钮时打开的菜单会正确同步。 所有菜单都在屏幕的左下方打开,如附图enter image description here

所示

应该在工具栏的特定按钮上。 这是 Toolbar.qml

的代码
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1

import UM 1.0 as UM

Item {
    id: base;

    width: buttons.width;
    height: buttons.height
    property int activeY

    Rectangle{
        id : bottomRow
        visible: true;
        width: menu.width
        height: buttons.height
        color: "#363636";
        anchors{
            bottom: parent.bottom
        }

        RowLayout {
            id: buttons;

            anchors.bottom: parent.bottom;
            anchors.horizontalCenter: parent.horizontalCenter;

            spacing: UM.Theme.getSize("button_lining").width
            Repeater {
                id: repeat

                model: UM.ToolModel { }

                Button {
                    text: model.name
                    iconSource: UM.Theme.getIcon(model.icon);

                    checkable: true;
                    checked: model.active;
                    enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled;

                    // style: UM.Theme.styles.tool_button;
                    style: UM.Theme.styles.tool_button_toolbar;

                    onCheckedChanged:
                    {
                        if(checked)
                        {
                            base.activeY = y
                        }
                    }
                    //Workaround since using ToolButton"s onClicked would break the binding of the checked property, instead
                    //just catch the click so we do not trigger that behaviour.
                    MouseArea {
                        anchors.fill: parent;
                        onClicked: {
                            forceActiveFocus() //First grab focus, so all the text fields are updated
                            if(parent.checked)
                            {
                                UM.Controller.setActiveTool(null)
                            }
                            else
                            {
                                UM.Controller.setActiveTool(model.id);
                            }
                        }
                    }
                }
            }
        }
    }

    UM.PointingRectangle {
        id: panelBorder;

        anchors.bottom: parent.top;
        anchors.bottomMargin: UM.Theme.getSize("default_margin").width;

        // anchors.top: base.top;
        anchors.topMargin: base.activeY

        z: buttons.z -1

        target: Qt.point(parent.right, base.activeY +  UM.Theme.getSize("button").height/2)
        arrowSize: UM.Theme.getSize("default_arrow").width

        width: {
            if (panel.item && panel.width > 0){
                 return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
            }
            else {
                return 0
            }
        }
        height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;

        opacity: panel.item && panel.width > 0 ? 1 : 0
        Behavior on opacity { NumberAnimation { duration: 100 } }

        color: UM.Theme.getColor("lining");

        UM.PointingRectangle {
            id: panelBackground;

            color: UM.Theme.getColor("tool_panel_background");
            anchors.fill: parent
            anchors.margins: UM.Theme.getSize("default_lining").width

            // target: Qt.point(-UM.Theme.getSize("default_margin").width, UM.Theme.getSize("button").height/2)
            // target: Qt.point(UM.Theme.getSize("default_margin").width, UM.Theme.getSize("button").height/2)
            arrowSize: parent.arrowSize
            MouseArea //Catch all mouse events (so scene doesnt handle them)
            {
                anchors.fill: parent
            }
        }

        Loader {
            id: panel

            x: UM.Theme.getSize("default_margin").width;
            y: UM.Theme.getSize("default_margin").height;

            source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "";
            enabled: UM.Controller.toolsEnabled;
        }
    }

    Rectangle
    {
        x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
        y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height

        width: toolHint.width + UM.Theme.getSize("default_margin").width
        height: toolHint.height;
        color: UM.Theme.getColor("tooltip")
        Label
        {
            id: toolHint
            text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
            color: UM.Theme.getColor("tooltip_text")
            font: UM.Theme.getFont("default")
            anchors.horizontalCenter: parent.horizontalCenter
        }

        visible: toolHint.text != "";
    }
}

请建议如何将菜单与特定的ToolBar按钮同步,以便它显示在该按钮的顶部。

0 个答案:

没有答案