#include "checkBoxDelegate.h"
#include <QtGui>
CheckBoxDelegate
::CheckBoxDelegate(QObject *parent
){
qDebug("CheckBoxDelegate::CheckBoxDelegate(): constructing delegate");
}
{
qDebug("CheckBoxDelegate::paint(): painting the delegate");
if(!model)
if(index.data() == 2)
{
}else{
}
}
{
qDebug("CheckBoxDelegate::createEditor(): create checkbox");
if(!model)
if(QVariant(model
->data
(index, Qt
::EditRole)).
toInt() == 2) checkbox->setCheckState(Qt::Checked);
else
checkbox->setCheckState(Qt::Unchecked);
return checkbox;
}
{
qDebug("CheckBoxDelegate::setEditorData(): set editor data");
QCheckBox *checkbox
= qobject_cast<QCheckBox
*>
(editor
);
if(!checkbox)
if(QVariant(model
->data
(index, Qt
::EditRole)).
toInt() == 2) checkbox->setCheckState(Qt::Checked);
else
checkbox->setCheckState(Qt::Unchecked);
}
{
qDebug("CheckBoxDelegate::setModelData(): Set model data");
if(!index.isValid())
return;
}
#include "checkBoxDelegate.h"
#include <QtGui>
CheckBoxDelegate::CheckBoxDelegate(QObject *parent)
:QItemDelegate(parent)
{
qDebug("CheckBoxDelegate::CheckBoxDelegate(): constructing delegate");
}
void CheckBoxDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
qDebug("CheckBoxDelegate::paint(): painting the delegate");
const QAbstractItemModel *model = index.model();
if(!model)
QItemDelegate::paint(painter, option, index);
if(index.data() == 2)
{
painter->fillRect(option.rect, QBrush(QColor("green")));
}else{
painter->fillRect(option.rect, QBrush(QColor("red")));
}
}
QWidget *CheckBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option , const QModelIndex &index) const
{
qDebug("CheckBoxDelegate::createEditor(): create checkbox");
const QAbstractItemModel *model = index.model();
if(!model)
QItemDelegate::createEditor(parent, option, index);
QCheckBox *checkbox = new QCheckBox(parent);
if(QVariant(model->data(index, Qt::EditRole)).toInt() == 2)
checkbox->setCheckState(Qt::Checked);
else
checkbox->setCheckState(Qt::Unchecked);
return checkbox;
}
void CheckBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
qDebug("CheckBoxDelegate::setEditorData(): set editor data");
QCheckBox *checkbox = qobject_cast<QCheckBox *>(editor);
if(!checkbox)
return QItemDelegate::setEditorData(editor, index);
const QAbstractItemModel *model = index.model();
if(QVariant(model->data(index, Qt::EditRole)).toInt() == 2)
checkbox->setCheckState(Qt::Checked);
else
checkbox->setCheckState(Qt::Unchecked);
}
void CheckBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
qDebug("CheckBoxDelegate::setModelData(): Set model data");
if(!index.isValid())
return;
return QItemDelegate::setModelData(editor, model, index);
}
To copy to clipboard, switch view to plain text mode
Bookmarks