QDesignerPropertySheetExtension Class
QDesignerPropertySheetExtensionクラスを使用すると、Qt Designer'のプロパティエディタに表示されるウィジェットのプロパティを操作することができます。詳細...
ヘッダー | #include <QDesignerPropertySheetExtension> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Designer) target_link_libraries(mytarget PRIVATE Qt6::Designer) |
qmake: | QT += designer |
パブリック関数
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は、ウィジェットのプロパティを照会したり、プロパティエディタでプロパティの外観を操作したりするために通常使用される関数のコレクションを提供します。例えば
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はQDesignerPropertySheetExtensionを使用してプロパティ・エディタをフィードします。ワークスペースでウィジェットが選択されると、 Designer はそのウィジェットのプロパティ シート拡張を照会します。選択されたウィジェットに実装されたプロパティシート拡張がある場合、この拡張はデフォルトのプロパティシートをオーバーライドします。Qt Widgets
- プロパティ・シートで使用されるデータ型は、Qt のデータ型ではなく、追加情報を含むQVariant の不透明なカスタム型です。例えば、列挙、フラグ、アイコン、pixmap、文字列がそうです。
- 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 では、4 種類のエクステンションを使用できます:QDesignerContainerExtension QDesignerMemberSheetExtension QDesignerTaskMenuExtension 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 、および「カスタム ウィジェット拡張機能の作成」も参照してください 。
メンバー関数ドキュメント
[virtual constexpr noexcept]
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 が真であれば、与えられたindex のプロパティは、UIファイルから除外される属性となる。
indexOf() およびisAttribute()も参照してください 。
[pure virtual]
void QDesignerPropertySheetExtension::setChanged(int index, bool changed)
指定されたindex のプロパティがデフォルト値と異なるかどうかを、changed パラメータによって設定する。
[pure virtual]
void QDesignerPropertySheetExtension::setProperty(int index, const QVariant &value)
与えられたindex にプロパティのvalue を設定します。
警告 この関数を使用してプロパティの値を変更した場合、元に戻すスタックは更新されません。元に戻すスタックを使用してプロパティの値を確実に元に戻すには、代わりに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 のプロパティ・エディタで表示されます。
© 2025 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.