2017-04-15 90 views
2

我有我自己的委托ListView。QML:调整CheckBox的大小

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.0 

ItemDelegate 
{ 
    height: 40 

    Row 
    { 
     spacing: 10 
     anchors.verticalCenter: parent.verticalCenter 

     CheckBox 
     { 

     } 
    } 
} 

问题是,尽管ItemDelegate的高度,复选框不会调整大小。

我得到这个身高= 40:

enter image description here

我得到这个身高= 10:

enter image description here

我试着玩CheckBox'es width和height价值观 - 没有帮助。

是否有可能使其更小,而无需自定义它?

回答

1

恐怕您需要customize您的复选框才能获得不同的尺寸。

例子:

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQml 2.2 

ApplicationWindow { 
    visible: true 
    width: 640 
    height: 480 
    title: qsTr("Hello World") 

    Component { 
     id: contactDelegate 

     ItemDelegate 
     { 
      id: item 
      width: 40 
      height: 40 

      CheckBox 
      { 
       id: control 
       text: name 

       indicator: Rectangle { 
        implicitWidth: item.width 
        implicitHeight: item.height 
        x: control.leftPadding 
        y: parent.height/2 - height/2 
        border.color: control.down ? "#dark" : "#grey" 

        Rectangle { 
         width: 25 
         height: 25 
         x: 7 
         y: 7 
         color: control.down ? "#dark" : "#grey" 
         visible: control.checked 
        } 
       } 
      } 
     } 
    } 

    ListView { 
     width: 180; 
     height: 200; 
     spacing: 10 

     model: ContactModel {} 
     delegate: contactDelegate 
    } 
} 

顺便说一句,在spacing属性应该在你的ListView,不委托进行设置。否则,它不起作用。

1

可以在理论上,增加指标的大小,但它不会增加复选标记图像的大小:

CheckBox { 
    text: "CheckBox" 
    anchors.centerIn: parent 
    checked: true 

    indicator.width: 64 
    indicator.height: 64 
} 

有几个为什么图像不进行缩放的原因。首先,如果增加了对号,对号将会模糊。更重要的是,保持最佳表现。 Qt Quick Controls 2并没有计算所有相互之间的大小,而是创建了大量的绑定,Qt Quick Controls 2将其可扩展性基于Qt 5.6中引入的自动高DPI缩放系统。以比例因子N运行时,您可以获得简单的@Nx图像。

相关问题