Change shape of a custom QtQuick Control template

I’m currently writing a custom style module for my QML application (using Qt 6.6.1). I don’t want to reinvent the wheel and rewrite the whole backend of basic controls, so I’m using the QtQuick Control template method, as decribed here.

My problem is that I want to create a SpinBox with rounded corner, like on the following design :

SpinBox design

I achieve to round the corners of the text field by applying a radius to the background property’s Rectangle. But I find hard to round the corner of the + and - buttons.

SpinBox generated by qml

My first idea was to have a kind of parent rounded Rectangle with clip: true, but I can’t do this with the Quick Control Template method. The root Item must be T.SpinBox, and I cannot set another parent to sub-elements properties like background, up.indicator, down.indicator and contentItem

Here is my current code :

import QtQuick
import QtQuick.Controls.impl
import QtQuick.Templates as T


T.SpinBox {
    id: control

    implicitWidth: background.implicitWidth
                   + up.indicator.width
                   + leftPadding
                   + rightPadding

    implicitHeight: background.implicitHeight
                    + topPadding
                    + bottomPadding

    leftPadding: padding
                 + (control.mirrored ?
                        (up.indicator ?
                            up.indicator.width
                            : 0
                        )
                        : (down.indicator ?
                            down.indicator.width
                            : 0
                        )
                    )

    rightPadding: padding
                  + (control.mirrored ?
                         (down.indicator ?
                            down.indicator.width
                            : 0)
                        : (up.indicator ?
                            up.indicator.width
                            : 0
                        )
                    )

    wheelEnabled: true
    editable: true
    font: Theme.fonts.controlText

    validator: IntValidator {
        locale: control.locale.name
        bottom: Math.min(control.from, control.to)
        top: Math.max(control.from, control.to)
    }

    contentItem: TextInput {
        id: textField
        z: 2
        text: control.displayText
        clip: width < implicitWidth

        font: control.font
        color: Theme.colors.textDisabled
        selectionColor: control.palette.highlight
        selectedTextColor: control.palette.highlightedText
        horizontalAlignment: Qt.AlignHCenter
        verticalAlignment: Qt.AlignVCenter
        anchors.left: parent.left
        anchors.right: up.indicator.left
        anchors.top: parent.top
        anchors.bottom: parent.bottom

        readOnly: !control.editable
        validator: control.validator
        inputMethodHints: control.inputMethodHints
    }

    up.indicator: Rectangle {
        id: upIndicator
        implicitWidth: 12
        implicitHeight: 9
        height: parent.height / 2
        anchors.right: parent.mirrored ? undefined : parent.right
        anchors.left: parent.mirrored ? parent.left : undefined
        anchors.top: parent.top
        color: "red"
    }

    down.indicator: Rectangle {
        id: downIndicator
        implicitWidth: 12
        implicitHeight: 9
        height: parent.height / 2
        color: "blue"

        anchors.right: parent.mirrored ? undefined : parent.right
        anchors.left: parent.mirrored ? parent.left : undefined
        anchors.bottom: parent.bottom
    }

    background: Rectangle {
        id: backgroundRectangle
        implicitWidth: 30
        implicitHeight: 18
        color: "green"
        border.width: 0
        radius: 2
    }
}

I’ve also tried to set Items to SpinBox fields properties, from Items instancied elsewhere (in a clipping Rectangle for example, but it didn’t cropped the items :

//imports

T.SpinBox {

    //... some size management

    contentItem: textField
    up.indicator: upIndicator
    down.indicator: downIndicator
    background: backgroundRectangle

    Rectangle {
        id: clippingRectangle
        anchors.fill: parent
        radius: 2
        clip: true

        TextInput {
            id: textField
            //...
        }

        Rectangle {
            id: upIndicator
            //...
        }

        Rectangle {
            id: downIndicator
            //...
        }

        Rectangle {
            id: backgroundRectangle
            //...
        }
    }
}

I’ve also tried to work with Layers and MultiEffect to put a mask on different items, without success again

import QtQuick.Effects

T.SpinBox {

    //... Size management + assign different fields as in first exemple

    Rectangle {
        id: maskRectangle
        color: "transparent"
        radius: 2
        anchors.fill: control
        border.width: 1
        border.color: Theme.colors.widgetBorder
        z: 3
    }

    layer.enabled: true
    MultiEffect {                  // Mask whole control -> doesn't works !
        source: control
        anchors.fill: control
        maskEnabled: true
        maskSource: maskRectangle
    }

    MultiEffect {                  // Mask up and down indicator items -> doesn't works !
        source: upIndicator
        anchors.fill: upIndicator
        maskEnabled: true
        maskSource: maskRectangle
    }
}

I’m out of ideas to achive this design. I would prefer to don’t rewrite a full custom spinBox from scratch. I like the way that the custom style works, and can adapt controls depending on application stye.
Does anyone have any idea or clues to help me ?

New contributor

Lucas Terrier is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật