#include "checkboxdelegate.h"
#include <QDebug>
CheckboxDelegate
::CheckboxDelegate(QObject *parent
) : QStyledItemDelegate(parent)
{
}
return editor;
}
bool value = index.model()->data(index, Qt::EditRole).toBool();
qDebug() << value;
QCheckBox *check
= static_cast<QCheckBox
*>
(editor
);
check->setChecked(value);
}
QCheckBox *check
= static_cast<QCheckBox
*>
(editor
);
model->setData(index, check->isChecked(), Qt::EditRole);
qDebug() << "setModelData" << check->isChecked();
}
void CheckboxDelegate
::updateEditorGeometry(QWidget *editor,
editor->setGeometry(option.rect);
}
#include "checkboxdelegate.h"
#include <QDebug>
CheckboxDelegate::CheckboxDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QWidget* CheckboxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
QCheckBox *editor = new QCheckBox(parent);
return editor;
}
void CheckboxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
bool value = index.model()->data(index, Qt::EditRole).toBool();
qDebug() << value;
QCheckBox *check = static_cast<QCheckBox*>(editor);
check->setChecked(value);
}
void CheckboxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
QCheckBox *check = static_cast<QCheckBox*>(editor);
model->setData(index, check->isChecked(), Qt::EditRole);
qDebug() << "setModelData" << check->isChecked();
}
void CheckboxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
editor->setGeometry(option.rect);
}
To copy to clipboard, switch view to plain text mode
Bookmarks