gast23
5th September 2010, 12:15
Hi,
i wrote a little itemdelegate for my tableview:
#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);
}
Everything works fine. If i click on a cell the editor poups up and i'm able to edit the value.
Now i would like that the editor is always displayed (User sees always the checkbox)
It this possible?
Thanks
i wrote a little itemdelegate for my tableview:
#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);
}
Everything works fine. If i click on a cell the editor poups up and i'm able to edit the value.
Now i would like that the editor is always displayed (User sees always the checkbox)
It this possible?
Thanks