2017-02-12 18 views
-1

我有一個抽屜,內側有一個按鈕,它設置爲抽屜寬度,但按下按鈕比抽屜長。按鈕比它應該更長

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

+0

請發表您的解決方案作爲一個合適的回答,不是編輯。在SO上不允許用答案編輯問題。謝謝。 – BaCaRoZzo

回答

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 
     } 
    } 
} 
+0

它沒有改變任何東西,亮點仍然太長。 –

0

SOLUTION: 你必須使自己的QML與按鈕,代碼來自:

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

,並從那裏編輯紋波的財產:

width: parent.width 

width: control.implicitWidth