QAbstractItemModel をサブクラス化し、dataChanged シグナルのスロットでウィジェットを取得しようとしています。
connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(slotDataChanged(const QModelIndex&, const QModelIndex&)));
void MyEditor::slotDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
QComboBox* widget = dynamic_cast<QComboBox*>(sender());
if (widget)
{
// do something
}
}
ここでは、毎回 null ウィジェットを取得していますが、qobject_cast と同じ結果です。
テーブルビューでQStyledItemDelegateを派生させるデリゲートクラスにコンボボックスウィジェットを設定しています。
MyDelegate* myDelegate;
myDelegate = new MyDelegate();
tableView->setItemDelegate(myDelegate);
tableView->setModel(model);
QWidget* MyDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QComboBox* cb = new QComboBox(parent);
cb->addItem(QString("All"));
cb->setCurrentIndex(0);
return cb;
}
この場合、送信者オブジェクトを取得するにはどうすればよいですか? ありがとう。