class pcheckboxdelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
pcheckboxdelegate
(QObject *parent
= 0) : QStyledItemDelegate
(parent
) {}
{
return editor;
}
{
bool value = index.model()->data(index, Qt::DisplayRole).toBool();
QCheckBox *checkBox
= static_cast<QCheckBox
*>
(editor
);
if (value == true ) {
checkBox->setCheckState(Qt::Checked);
} else {
checkBox->setCheckState(Qt::Unchecked);
}
}
{
QCheckBox *checkBox
= static_cast<QCheckBox
*>
(editor
);
if(checkBox->checkState() == Qt::Checked) {
model->setData(index, true);
} else {
model->setData(index, true);
}
}
void updateEditorGeometry
(QWidget *editor,
{
editor->setGeometry(option.rect);
}
};
class pcheckboxdelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
pcheckboxdelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {}
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QCheckBox *editor = new QCheckBox(parent);
return editor;
}
void setEditorData(QWidget *editor, const QModelIndex &index) const
{
bool value = index.model()->data(index, Qt::DisplayRole).toBool();
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
if (value == true ) {
checkBox->setCheckState(Qt::Checked);
} else {
checkBox->setCheckState(Qt::Unchecked);
}
}
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
if(checkBox->checkState() == Qt::Checked) {
model->setData(index, true);
} else {
model->setData(index, true);
}
}
void 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