Search code examples
qtqmlqtquickcontrols2

QML: Resize CheckBox


I have ListView with my own delegate.

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
        {

        }
    }
}

The problem is that check boxes does not resize despite ItemDelegate's height.

I get this for height = 40:

enter image description here

I get this for height = 10:

enter image description here

I've tried playing with CheckBox'es width and height values - did not help.

Is it possible to make it smaller at all, without customizing it?


Solution

  • You can, in theory, increase the size of the indicator, but it won't increase the size of the checkmark image:

    CheckBox {
        text: "CheckBox"
        anchors.centerIn: parent
        checked: true
    
        indicator.width: 64
        indicator.height: 64
    }
    

    There are a couple of reasons why the image is not scaled. First of all, the checkmark would be blurry if it was upscaled. And more importantly, to retain best possible performance. Instead of calculating all the sizes relative to each other and that way creating huge amounts of bindings like Qt Quick Controls 1 did, Qt Quick Controls 2 bases its scalability instead on the automatic high-DPI scaling system introduced in Qt 5.6. You get simply a different @Nx image when running with scale factor N.