このページでは

QDesignerPropertySheetExtension Class

QDesignerPropertySheetExtension クラスを使用すると、Qt Designer のプロパティエディタに表示されるウィジェットのプロパティを操作することができます。詳細...

ヘッダー: #include <QDesignerPropertySheetExtension>
CMake: find_package(Qt6 REQUIRED COMPONENTS Designer)
target_link_libraries(mytarget PRIVATE Qt6::Designer)
qmake: QT += designer

パブリック関数

QDesignerPropertySheetExtension()
QDesignerPropertySheetExtension(const QDesignerPropertySheetExtension &)
QDesignerPropertySheetExtension(QDesignerPropertySheetExtension &&)
virtual ~QDesignerPropertySheetExtension()
virtual int count() const = 0
virtual bool hasReset(int index) const = 0
virtual int indexOf(const QString &name) const = 0
virtual bool isAttribute(int index) const = 0
virtual bool isChanged(int index) const = 0
virtual bool isEnabled(int index) const = 0
virtual bool isVisible(int index) const = 0
virtual QVariant property(int index) const = 0
virtual QString propertyGroup(int index) const = 0
virtual QString propertyName(int index) const = 0
virtual bool reset(int index) = 0
virtual void setAttribute(int index, bool attribute) = 0
virtual void setChanged(int index, bool changed) = 0
virtual void setProperty(int index, const QVariant &value) = 0
virtual void setPropertyGroup(int index, const QString &group) = 0
virtual void setVisible(int index, bool visible) = 0
QDesignerPropertySheetExtension &operator=(QDesignerPropertySheetExtension &&)
QDesignerPropertySheetExtension &operator=(const QDesignerPropertySheetExtension &)

詳細な説明

QDesignerPropertySheetExtension は、通常、ウィジェットのプロパティを照会したり、プロパティエディタでのプロパティの表示を操作したりするために使用される一連の関数を提供します。例:

QDesignerPropertySheetExtension *propertySheet = nullptr;
QExtensionManager manager = formEditor->extensionManager();

propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
int index = propertySheet->indexOf(u"margin"_s);

propertySheet->setProperty(index, 10);
propertySheet->setChanged(index, true);

delete propertySheet;

QDesignerPropertySheetExtension::setProperty() 関数を使用してプロパティの値を変更した場合、元に戻すスタックは更新されないことに注意してください。元に戻すスタックを使用してプロパティの値を元に戻せるようにするには、代わりにQDesignerFormWindowCursorInterface::setProperty() 関数、またはそのバディ関数であるsetWidgetProperty() を使用する必要があります。

カスタムウィジェットプラグインを実装する場合、Qt Widgets Designer の現在のQDesignerFormEditorInterface オブジェクト(上記の例ではformEditor )へのポインタは、QDesignerCustomWidgetInterface::initialize()関数のパラメータとして提供されます。

プロパティシートやその他の拡張機能は、qt_extension() 関数を使用してQt Widgets Designer の拡張機能マネージャーにクエリを実行することで取得できます。拡張機能を解放したい場合は、ポインタを削除するだけで済みます。

すべてのウィジェットにはデフォルトのプロパティシートがあり、Qt Widgets Designer のプロパティエディタにウィジェットのプロパティ(つまり、Q_PROPERTY() マクロで定義されたもの)が表示されます。しかし、QDesignerPropertySheetExtensionは、カスタムプロパティシート拡張機能を作成するためのインターフェースも提供しています。

以下の制限事項に注意してください:

  • Qt Widgets Designer Qt Widgets Designer は、QDesignerPropertySheetExtensionを使用してプロパティエディタにデータを供給します。ワークスペースでウィジェットが選択されるたびに、 はそのウィジェットのプロパティシート拡張機能を照会します。選択されたウィジェットに実装済みのプロパティシート拡張機能がある場合、その拡張機能がデフォルトのプロパティシートを上書きします。
  • 一部のプロパティにおいて、プロパティシートで使用されるデータ型は、単純なQtデータ型ではなく、追加情報を含む不透明なQVariant のカスタム型です。例えば、列挙型、フラグ、アイコン、ピクマップ、文字列などがこれに該当します。
  • Qt Widgets Designerの プロパティエディタには、Q_DECLARE_METATYPE() で宣言されたカスタム型に対する `Q_PROPERTY ` 型の処理実装がありません。

プロパティシート拡張機能を作成するには、拡張クラスがQObject とQDesignerPropertySheetExtensionの両方を継承する必要があります。また、インターフェースを実装しているため、Q_INTERFACES()マクロを使用して、そのインターフェースがメタオブジェクトシステムに認識されるようにする必要があります:

class MyPropertySheetExtension : public QObject,
        public QDesignerPropertySheetExtension
{
    Q_OBJECT
    Q_INTERFACES(QDesignerPropertySheetExtension)

public:
    ...
}

これにより、Qt Widgets Designer はqobject_cast()を使用して、QObject ポインタのみを基に、サポートされているインターフェースを照会できるようになります。

Qt Widgets Designer では、拡張機能は必要になるまで作成されません。そのため、プロパティシート拡張機能を実装する際は、QExtensionFactory (つまり、拡張機能のインスタンスを作成できるクラス)も作成し、Qt Widgets Designer のextension manager を使用して登録する必要があります。

プロパティシート拡張機能が要求されると、Qt Widgets Designer のextension manager は、登録されているすべてのファクトリを順に処理し、それぞれに対してQExtensionFactory::createExtension()を呼び出し、選択されたウィジェット用のプロパティシート拡張機能を作成できる最初のファクトリが見つかるまで続けます。その後、そのファクトリが拡張機能のインスタンスを作成します。そのようなファクトリが見つからない場合、Qt Widgets Designer はデフォルトのプロパティシートを使用します。

Qt Widgets Designer では、QDesignerContainerExtension 、QDesignerMemberSheetExtension 、QDesignerPropertySheetExtension、QDesignerTaskMenuExtension の 4 種類の拡張機能が利用可能です。Qt Designer の動作は、要求された拡張機能がマルチページコンテナ、メンバーシート、プロパティシート、またはタスクメニューのいずれに関連付けられているかに関わらず同じです。

QExtensionFactory クラスは標準の拡張機能ファクトリを提供するほか、カスタム拡張機能ファクトリのインターフェースとしても使用できます。新しいQExtensionFactory を作成し、QExtensionFactory::createExtension()関数を再実装することも可能です。例:

QObject *ANewExtensionFactory::createExtension(QObject *object,
        const QString &iid, QObject *parent) const
{
    if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
        return 0;

    if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
           (object))
        return new MyPropertySheetExtension(widget, parent);

    return 0;
}

あるいは、既存のファクトリを使用し、QExtensionFactory::createExtension() 関数を拡張して、そのファクトリがプロパティシート拡張機能も作成できるようにすることもできます。例:

QObject *AGeneralExtensionFactory::createExtension(QObject *object,
        const QString &iid, QObject *parent) const
{
    MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);

    if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
        return new MyTaskMenuExtension(widget, parent);

    } else if (widget && (iid == Q_TYPEID(QDesignerPropertySheetExtension))) {
        return new MyPropertySheetExtension(widget, parent);

    } else {
        return 0;
    }
}

拡張クラスを使用した完全な例については、「タスクメニュー拡張」の例を参照してください。この例では、Qt Designer 用のカスタムウィジェットプラグインの作成方法、およびQDesignerTaskMenuExtension クラスを使用してQt Widgets Designer のタスクメニューにカスタム項目を追加する方法が示されています。

関連項目: QDesignerDynamicPropertySheetExtension 、QExtensionFactory 、QExtensionManager 、および「カスタムウィジェット拡張機能の作成」を参照してください 。

メンバ関数のドキュメント

[constexpr noexcept default] QDesignerPropertySheetExtension::QDesignerPropertySheetExtension()

QDesignerPropertySheetExtension のインスタンスをデフォルトコンストラクタで生成します。

[delete] QDesignerPropertySheetExtension::QDesignerPropertySheetExtension(const QDesignerPropertySheetExtension &)

QDesignerPropertySheetExtension のインスタンスをコピーして生成します。この関数は削除されています。

[delete] QDesignerPropertySheetExtension::QDesignerPropertySheetExtension(QDesignerPropertySheetExtension &&)

QDesignerPropertySheetExtension のインスタンスをMoveコンストラクタで生成します。この関数は削除されています。

[virtual constexpr noexcept default] QDesignerPropertySheetExtension::~QDesignerPropertySheetExtension()

プロパティシート拡張機能を削除します。

[pure virtual] int QDesignerPropertySheetExtension::count() const

選択されたウィジェットのプロパティ数を返します。

[pure virtual] bool QDesignerPropertySheetExtension::hasReset(int index) const

指定されたindex にあるプロパティが、Qt Widgets Designer のプロパティエディタにリセットボタンを有している場合はtrueを返し、そうでない場合はfalseを返します。

indexOf() およびreset()も参照してください 。

[pure virtual] int QDesignerPropertySheetExtension::indexOf(const QString &name) const

指定されたプロパティ `name` のインデックスを返します。

propertyName()も参照してください 。

[pure virtual] bool QDesignerPropertySheetExtension::isAttribute(int index) const

指定されたindex にあるプロパティが属性である場合、そのプロパティはUIファイルから除外されるためtrueを返します。そうでない場合はfalseを返します。

indexOf() およびsetAttribute()も参照してください 。

[pure virtual] bool QDesignerPropertySheetExtension::isChanged(int index) const

指定されたindex におけるプロパティの値が、そのプロパティのデフォルト値と異なる場合はtrueを返し、そうでない場合はfalseを返します。

indexOf()、setChanged()、およびreset()も参照してください 。

[pure virtual] bool QDesignerPropertySheetExtension::isEnabled(int index) const

指定されたindex にあるプロパティが、Qt Widgets Designer のプロパティエディタで有効になっている場合はtrueを返し、そうでない場合はfalseを返します。

indexOf()も参照してください 。

[pure virtual] bool QDesignerPropertySheetExtension::isVisible(int index) const

指定されたindex にあるプロパティが、Qt Widgets Designer のプロパティエディタに表示されている場合はtrueを返し、そうでない場合はfalseを返します。

indexOf() およびsetVisible()も参照してください 。

[pure virtual] QVariant QDesignerPropertySheetExtension::property(int index) const

指定されたindex におけるプロパティの値を返します。

indexOf()、setProperty()、およびpropertyGroup()も参照してください 。

[pure virtual] QString QDesignerPropertySheetExtension::propertyGroup(int index) const

指定されたindex にあるプロパティのプロパティグループを返します。

Qt Widgets Designer'のプロパティエディタは、プロパティグループ、すなわち関連するプロパティのセクションをサポートしています。プロパティは、setPropertyGroup() 関数を使用してグループに関連付けることができます。どのプロパティのデフォルトのグループも、そのプロパティを定義するクラスの名前になります。例えば、QObject::objectName プロパティは、QObject プロパティグループ内に表示されます。

indexOf() およびsetPropertyGroup()も参照してください 。

[pure virtual] QString QDesignerPropertySheetExtension::propertyName(int index) const

指定されたindex にあるプロパティの名前を返します。

indexOf()も参照してください 。

[pure virtual] bool QDesignerPropertySheetExtension::reset(int index)

指定されたindex のプロパティの値を、デフォルト値にリセットします。デフォルト値が見つかった場合はtrueを返し、見つからなかった場合はfalseを返します。

indexOf()、hasReset()、およびisChanged()も参照してください 。

[pure virtual] void QDesignerPropertySheetExtension::setAttribute(int index, bool attribute)

attribute が true の場合、指定されたindex にあるプロパティは、UI ファイルから除外される属性として扱われます。そうでない場合は、UI ファイルに含まれます。

indexOf() およびisAttribute()も参照してください 。

[pure virtual] void QDesignerPropertySheetExtension::setChanged(int index, bool changed)

changed パラメータの設定に応じて、指定されたindex のプロパティがデフォルト値と異なるかどうかを設定します。

indexOf() およびisChanged()も参照してください 。

[pure virtual] void QDesignerPropertySheetExtension::setProperty(int index, const QVariant &value)

プロパティのvalue を、指定されたindex に設定します。

警告: この関数を使用してプロパティの値を変更した場合 、元に戻すスタックは更新されません。元に戻すスタックを使用してプロパティの値を元に戻せるようにするには、代わりに `QDesignerFormWindowCursorInterface::setProperty()` 関数、またはその関連関数である `setWidgetProperty()` を使用する必要があります。

関連項目: indexOf()、property()、およびpropertyGroup()。

[pure virtual] void QDesignerPropertySheetExtension::setPropertyGroup(int index, const QString &group)

指定されたindex にあるプロパティのプロパティグループを、group に設定します。

プロパティをグループに関連付けると、そのプロパティはプロパティエディタの当該グループのセクション内に表示されるようになります。どのプロパティのデフォルトのプロパティグループも、そのプロパティを定義するクラスの名前になります。たとえば、QObject::objectName プロパティは、QObject プロパティグループ内に表示されます。

「 indexOf()」、「property()」、および「propertyGroup()」も参照してください 。

[pure virtual] void QDesignerPropertySheetExtension::setVisible(int index, bool visible)

visible がtrueの場合、指定されたindex にあるプロパティは、Qt Widgets Designer のプロパティエディタに表示されます。そうでない場合、そのプロパティは非表示になります。

indexOf() およびisVisible()も参照してください 。

[delete] QDesignerPropertySheetExtension &QDesignerPropertySheetExtension::operator=(QDesignerPropertySheetExtension &&)

other をこのQDesignerPropertySheetExtension インスタンスに割り当てます。この関数は削除されます。

[delete] QDesignerPropertySheetExtension &QDesignerPropertySheetExtension::operator=(const QDesignerPropertySheetExtension &)

other をこのQDesignerPropertySheetExtension インスタンスにコピー代入します。この関数は削除されます。

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