按钮比它应该长

时间:2017-02-12 20:07:35

标签: android qt qml qtquick2 qtquickcontrols2

我有一个抽屉,并在其旁边放置一个按钮,该按钮设置为抽屉宽度,但按下的按钮比抽屉长。

enter image description here

Drawer {
     id: drawer
     width: 0.66 * parent.width
     height: parent.height

     background: Rectangle {
         color: "#212121"
         anchors.fill: parent
      }

     ColumnLayout {
         Button {
             onClicked: {
                 drawer.close()
             }
             text: "<font color=\"#ffffff\">Lorem</font>"
             implicitHeight: 60
             implicitWidth: drawer.width
             flat: true
             Material.theme: Material.Dark
             Material.elevation: 0
         }
     }
 }

这不是关于半径,我把它设置为0,这就是我得到的,当没有按下时它甚至更长。

enter image description here

2 个答案:

答案 0 :(得分:0)

使用Layout.rightMargin对象类型的ColumnLayout属性为列布局添加右边距

http://doc.qt.io/qt-5/qml-qtquick-layouts-layout.html#margins-attached-prop

Drawer {
     id: drawer
     width: 0.66 * parent.width
     height: parent.height

     background: Rectangle {
         color: "#212121"
         anchors.fill: parent
      }

     ColumnLayout {

         /* add Layout Margin here */
         Layout.rightMargin: 10
         /*   */

         Button {
             onClicked: {
                 drawer.close()
             }
             text: "<font color=\"#ffffff\">Lorem</font>"
             implicitHeight: 60
             implicitWidth: drawer.width
             flat: true
             Material.theme: Material.Dark
             Material.elevation: 0
         }
     }
 }

答案 1 :(得分:0)

<强>解: 您必须使用按钮创建自己的QML,代码来自:

$ QTDIR / QML / QtQuick / Controls.2 / Button.qml

并编辑Ripple的属性:

width: control.implicitWidth

{{1}}