このページでは

QSqlRelationalDelegate Class

QSqlRelationalDelegate クラスは、QSqlRelationalTableModel からのデータの表示や編集に使用されるデリゲートを提供します。詳細...

ヘッダー: #include <QSqlRelationalDelegate>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sql)
target_link_libraries(mytarget PRIVATE Qt6::Sql)
qmake: QT += sql
継承元: QStyledItemDelegate

パブリック関数

QSqlRelationalDelegate(QObject *parent = nullptr)
virtual ~QSqlRelationalDelegate()

再実装されたパブリック関数

virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override

詳細な説明

デフォルトのデリゲートとは異なり、QSqlRelationalDelegate は、他のテーブルへの外部キーとなるフィールドに対してコンボボックスを提供します。このクラスを使用するには、QSqlRelationalDelegate のインスタンスを使用して、ビューに対して `QAbstractItemView::setItemDelegate()` を呼び出すだけです。

    std::unique_ptr<QTableView> view{new QTableView};
    view->setModel(model);
    view->setItemDelegate(new QSqlRelationalDelegate(view.get()));

「リレーショナルテーブルモデル」の例(以下に示す)は、QSqlRelationalTableModel と組み合わせて QSqlRelationalDelegate を使用し、テーブルに外部キーのサポートを提供する方法を示しています。

ユーザーは、リレーショナルテーブルの外部キーを編集することができます。

QSqlRelationalTableModel およびモデル・ビュープログラミングも参照してください 。

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

[explicit] QSqlRelationalDelegate::QSqlRelationalDelegate(QObject *parent = nullptr)

指定されたparent を使用して、QSqlRelationalDelegateオブジェクトを生成します。

[virtual noexcept] QSqlRelationalDelegate::~QSqlRelationalDelegate()

QSqlRelationalDelegate オブジェクトを破棄し、割り当てられたリソースをすべて解放します。

[override virtual] QWidget *QSqlRelationalDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

QStyledItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const を再実装します。

[override virtual] void QSqlRelationalDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const

QStyledItemDelegate::setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)const を再実装します。

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