Здравствуйте, есть делегат, но при его вызове он отображается не в таблице, а в отдельном окне, как можно это исправить?
#ifndef LOGICITEMDELEGATE_H
#define LOGICITEMDELEGATE_H
#include "QItemDelegate"
#include "QComboBox"
class logicItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
logicItemDelegate();
~logicItemDelegate();
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif
#include "logicItemDelegate.h"
#include "QComboBox"
#include "QDebug"
logicItemDelegate::logicItemDelegate()
: QItemDelegate()
{
}
logicItemDelegate::~logicItemDelegate()
{
}
QWidget *logicItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex &) const
{
QComboBox * comboBox = new QComboBox;
comboBox->addItem("Yes");
comboBox->addItem("No");
return comboBox;
}
void logicItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::DisplayRole).toString();
QComboBox * comboBox = static_cast<QComboBox*>(editor);
if(value == "Yes")
comboBox->setCurrentIndex(0);
else
comboBox->setCurrentIndex(1);
}
void logicItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QComboBox * comboBox = static_cast<QComboBox*>(editor);
model->setData(index, comboBox->currentText(), Qt::EditRole);
}
void logicItemDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &) const
{
editor->setGeometry(option.rect);
}
Заранее спасибо!
Сообщение отредактировал ruzik - 31.12.2011, 19:16