このページでは

CustomControl QML Type

カスタム(組み込みではない)コントロールのスタイルを定義します。詳細...

Import Statement: import Qt.labs.StyleKit
Inherits:

ControlStyle

Status: Technology preview

この型はテクノロジープレビュー段階にあり、変更される可能性があります。

プロパティ

詳細説明

CustomControl を使用すると、Qt Quick コントロールに含まれていないコントロールを定義し、スタイルを設定することができます。これは、アクティブなStyle およびTheme に基づいてスタイルを設定する必要がある追加のコントロールやコンポーネントがある場合に便利です。

組み込みのコントロール型(abstractButton 、pane 、slider など)と同様に、CustomControlはControlStyle を継承します。コントロール型に暗黙的に関連付けられている組み込み型とは異なり、CustomControlではcontrolType を明示的に設定する必要があります。それ以外は、動作がまったく同じです。

Style やTheme では、必要に応じて任意の数のカスタムコントロールを定義できます。また、テーマ内のCustomControlは、Style 内のものと同じcontrolType を持つことができます。これは、例えば、slider がStyle とTheme の両方によってスタイル設定される場合と何ら変わりません。フォールバックのロジックも同様です。

CustomControlに設定されていないスタイルプロパティは、control に設定されているものにフォールバックします。

以下のスニペットは、カスタムコントロールのスタイルを定義する方法を示しています:

// MyStyle.qml

Style {
    id: style
    readonly property int myControlType: 0
    CustomControl {
        controlType: style.myControlType
        background {
            width: 120
            height: 30
            radius: 0
        }
        hovered.background.color: "lightslategray"
        pressed.background.color: "skyblue"
    }
}

また、以下のスニペットは、それを使用するカスタムコントロールを実装する例を示しています:

// Main.qml

component MyControl : Rectangle {
    StyleReader {
        id: styleReader
        controlType: StyleKit.style.myControlType
        hovered: hoverHandler.hovered
        pressed: tapHandler.pressed
        palette: app.palette
    }

    HoverHandler { id: hoverHandler }
    TapHandler { id: tapHandler }

    implicitWidth: styleReader.background.width
    implicitHeight: styleReader.background.height
    color: styleReader.background.color
    radius: styleReader.background.radius

    Text {
        font: styleReader.font
        anchors.centerIn: parent
        text: "ok"
    }
}

注: Qt.labs モジュール内の型は、将来のバージョンでも互換性が維持されるとは限りません。

関連項目: StyleReader 、ControlStyle 、Style 、およびStylableControls::getControlStyle()。

プロパティのドキュメント

controlType : int

このカスタムコントロール型を識別する一意の整数です。カスタムコントロールの実装内のStyleReader.controlType に同じ値を設定することで、このスタイル定義に関連付けることができます。

カスタムコントロール型は、0 から100000 の範囲内である必要があります。

「 StyleReader.controlType 」および「StylableControls::getControlStyle()」も参照してください 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.