このページでは

CustomControl QML Type

カスタム(非内蔵)コントロールのスタイルを定義します。詳細...

Import Statement: import Qt.labs.StyleKit
Inherits:

ControlStyle

プロパティ

詳細説明

CustomControlを使用すると、.NET Frameworkの一部ではないコントロールを定義し、スタイルを設定することができます。 Qt Quick Controls.これは、アクティブなStyle およびTheme に従ってスタイルを設定する追加のコントロールまたはコンポーネントがある場合に便利です。

組み込みコントロール・タイプ(abstractButtonpaneslider など)と同様に、CustomControl はControlStyle を継承します。コントロール・タイプに暗黙的に接続されている組み込み型とは異なり、CustomControl はcontrolType を明示的に設定する必要があります。それを除けば、両者はまったく同じように動作します。

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

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

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

// MyStyle.qml

Style {
    id: style
    readonly property int myControlType: 0
    CustomControl {
        controlType: style.myControlType
        background {
            implicitWidth: 120
            implicitHeight: 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.implicitWidth
    implicitHeight: styleReader.background.implicitHeight
    color: styleReader.background.color
    radius: styleReader.background.radius

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

注意: Qt.lab モジュールの型は、将来のバージョンでも互換性が保たれることを保証するものではありません。

StyleReaderControlStyleStyleも参照して ください。

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

controlType : int

このカスタム・コントロール・タイプを識別する一意の整数。カスタム・コントロール実装のStyleReader.controlType に同じ値を設定して、このスタイル定義に接続します。

カスタム・コントロール・タイプは、0 から100000 の範囲になければなりません。

StyleReader.controlTypeも参照してください

© 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.