23 #include <QAbstractItemModel>
24 #include <QApplication>
26 #include <QModelIndex>
37 QStyledItemDelegate(parent), RowHeight(0), AddRowHeight(false)
47 const QModelIndex& index)
const
49 QWidget* tmpWidget =
nullptr;
53 tmpWidget = tmpProperty->
createEditor(parent, option,
this);
56 return tmpWidget ? tmpWidget : QStyledItemDelegate::createEditor(parent, option, index);
64 if (index.isValid() && editor)
72 QStyledItemDelegate::setEditorData(editor, index);
78 const QModelIndex & index)
const
81 if (index.isValid() && editor)
89 QStyledItemDelegate::setModelData(editor, model, index);
92 model->setData(index, tmpData);
97 QSize tmpStandardSizeHint = QStyledItemDelegate::sizeHint(option, index);
98 tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1);
102 return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight);
105 return tmpStandardSizeHint;
111 AddRowHeight = add_to_standard;
115 const QModelIndex& index )
const
118 if (index.isValid() && index.column() == 1)
120 done =
reinterpret_cast<VProperty*
>(index.internalPointer())->paint(painter, option, index,
this);
125 QStyledItemDelegate::paint(painter, option, index);
128 QColor tmpPenColor =
static_cast<QRgb
>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
130 QPen tmpOldPen = painter->pen();
131 painter->setPen(QPen(tmpPenColor));
132 painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom());
133 painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
134 painter->setPen(tmpOldPen);
virtual ~VPropertyDelegate() Q_DECL_OVERRIDE
void setRowHeight(int height=0, bool add_to_standard=false)
Sets the row height. Set this to 0 and the standard will be taken.
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE
Sets the index data to the editor.
VPropertyDelegate(QObject *parent=nullptr)
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE
Updates the index data.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
Returns the size hint.
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
Renders the delegate using the given painter and style option for the item specified by index.
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
Creates the editor widget.
virtual bool setEditorData(QWidget *editor)
Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual QVariant getEditorData(const QWidget *editor) const
Gets the data from the widget.
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QAbstractItemDelegate *)
Returns an editor widget, or NULL if it doesn't supply one.