QDesignerWidgetBoxInterface Class
QDesignerWidgetBoxInterface クラスを使用すると、Qt Widgets Designer のウィジェットボックスの内容を制御できます。詳細...
| ヘッダー: | #include <QDesignerWidgetBoxInterface> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Designer) target_link_libraries(mytarget PRIVATE Qt6::Designer) |
| qmake: | QT += designer |
| 継承元: | QWidget |
パブリック関数
| QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) | |
| virtual | ~QDesignerWidgetBoxInterface() override |
| virtual QString | fileName() const = 0 |
| virtual bool | load() = 0 |
| virtual bool | save() = 0 |
| virtual void | setFileName(const QString &fileName) = 0 |
詳細な説明
QDesignerWidgetBoxInterface には、通常、Qt Widgets Designer のウィジェットボックスの内容を操作するために使用される一連の関数が含まれています。
Qt Widgets Designer は、XML ファイルを使用してウィジェットボックスにデータを格納します。そのファイル名はウィジェットボックスのプロパティの 1 つであり、fileName() 関数を使用して取得できます。
QDesignerWidgetBoxInterface は、ウィジェットボックスの内容を、ウィジェットボックスのファイル名プロパティで指定されたファイルに保存する `save()` 関数も提供しています。save() 関数を呼び出さずに、ウィジェットボックスにウィジェットをドロップするなどして変更を加えた場合、load() 関数を呼び出すだけで、元のコンテンツを復元できます。
auto *widgetBox = formEditor->widgetBox();
widgetBox->load();QDesignerWidgetBoxInterface クラスは、直接インスタンス化することを意図したものではありません。QDesignerFormEditorInterface::widgetBox() 関数を使用して、Qt Designer のウィジェットボックスへのインターフェースを取得できます。Qt Widgets Designer の現在のQDesignerFormEditorInterface オブジェクト(上記の例ではformEditor )へのポインタは、QDesignerCustomWidgetInterface::initialize() 関数のパラメータとして提供されます。カスタムウィジェットプラグインを実装する際は、QDesignerCustomWidgetInterface をサブクラス化して、Qt Widgets Designer に対してプラグインを公開する必要があります。
変更内容を保存しつつ、元のコンテンツも保持したい場合は、save() 関数とsetFileName() 関数を組み合わせて、変更内容を別のファイルに保存することができます。その際、まず元のファイル名を保存しておくことを忘れないでください:
QString originalFile = widgetBox->fileName();
widgetBox->setFileName("myWidgetBox.xml");
widgetBox->save();その後、ファイル名を元のファイル名にリセットし、load() を呼び出すことで、ウィジェットボックスの元のコンテンツを復元できます:
widgetBox->setFileName(originalFile);
widgetBox->load();同様の方法で、後でカスタマイズしたXMLファイルを使用することができます:
if (widgetBox->filename() != "myWidgetBox.xml") {
widgetBox->setFileName("myWidgetBox.xml");
widgetBox->load();
}「QDesignerFormEditorInterface」も参照してください 。
メンバー関数のドキュメント
[explicit] QDesignerWidgetBoxInterface::QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
指定されたparent と、指定されたウィンドウflags を用いて、ウィジェットボックスインターフェースを構築します。
[override virtual noexcept] QDesignerWidgetBoxInterface::~QDesignerWidgetBoxInterface()
ウィジェットボックスのインターフェースを破棄します。
[pure virtual] QString QDesignerWidgetBoxInterface::fileName() const
Qt Widgets Designer が現在、ウィジェットボックスの表示に使用しているXMLファイルの名前を返します。
setFileName()も参照してください 。
[pure virtual] bool QDesignerWidgetBoxInterface::load()
現在指定されているXMLファイルを読み込み(または再読み込み)して、Qt Widgets Designer のウィジェットボックスにデータを設定します。ファイルの読み込みに成功した場合はtrueを返し、失敗した場合はfalseを返します。
setFileName()も参照してください 。
[pure virtual] bool QDesignerWidgetBoxInterface::save()
Qt Widgets Designer のウィジェットボックスの内容を、fileName()関数で指定されたファイルに保存します。内容が正常に保存された場合はtrueを返し、そうでない場合はfalseを返します。
fileName() およびsetFileName()も参照してください 。
[pure virtual] void QDesignerWidgetBoxInterface::setFileName(const QString &fileName)
Qt Widgets Designer がウィジェットボックスの内容を生成するために使用するXMLファイルを、fileName に設定します。新しいXMLファイルに基づいてウィジェットボックスを更新するには、load() を呼び出す必要があります。
© 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.