Loading [MathJax]/extensions/tex2jax.js
OGS
ColorTableView.cpp
Go to the documentation of this file.
1 
16 #include "ColorTableView.h"
17 
18 #include <QHeaderView>
19 #include <QPainter>
20 
21 ColorTableView::ColorTableView(QWidget* parent /*= 0*/) : QTableView(parent)
22 {
23  this->verticalHeader()->hide();
24  this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
25  this->resizeColumnsToContents();
26  this->resizeRowsToContents();
27 }
28 
29 void ColorTableViewDelegate::paint(QPainter* painter,
30  const QStyleOptionViewItem& option,
31  const QModelIndex& index) const
32 {
33  QColor val;
34  if (index.column() == 1)
35  {
36  if (index.data().canConvert(QMetaType::QColor))
37  {
38  val = index.data().value<QColor>();
39  QBrush brush(val);
40  painter->fillRect(option.rect, brush);
41  }
42  }
43  else
44  {
45  QItemDelegate::paint(painter, option, index);
46  }
47 }
48 
49 QSize ColorTableViewDelegate::sizeHint(const QStyleOptionViewItem& option,
50  const QModelIndex& index) const
51 {
52  QSize s = QItemDelegate::sizeHint(option, index);
53  if (s.isValid())
54  {
55  s.setHeight(static_cast<int>(0.5 * s.height()));
56  }
57  return s;
58 }
Definition of the ColorTableView class.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Overwrites the paint-method to set user-defined properties instead of the default properties.
ColorTableView(QWidget *parent=nullptr)
Constructor.