Answer the question
In order to leave comments, you need to log in
Is it possible to implement this on QTreeView and QStandardItemModel?
I made a craft on QTreeView and QStandardItemModel:
If the correlation between countries is briefly shown by some parameter (for example, the value of trade relations). The larger this parameter, the brighter the color in the cell. When you select a cell, the corresponding countries are highlighted. Everything seems to be fine, but I can't make the remaining "little things":
1) Colored cells make everything the same size.
I tried to do this in the data method, it did not help:
if (role == Qt::SizeHintRole)
{
if (isColorCell())
return QSize(50, 50);
}
QPalette p = palette();
p.setColor(QPalette::Highlight, QColor("#FFFFCC"));
p.setColor(QPalette::HighlightedText, Qt::black);
setPalette(p);
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect |
QItemSelectionModel::Rows |
QItemSelectionModel::Columns);
Answer the question
In order to leave comments, you need to log in
1) The size is set in the header (if I don’t confuse anything) And this way you can see by the triggering of events who drives what
2) No way, you already need to change the viewer
3) Change the corresponding event handler
You can do almost everything from what you want .
You need to inherit from QStyledItemDelegate
1. The size of the cell (the maximum desired) is issued from the delegate using the sizeHint method.
There are some subtleties when working with it, but if you add metaproperties to the data, you can change the size (but within reasonable limits )
2. You need to look at the selection in the paint delegate method
. For example, I did this
void myClass::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
...
//[In case of selection override colour to selection color except mean row]
if(QStyle::State_Selected & option.state)
{
QColor selectedColor = QApplication::palette().color(QPalette::Highlight);
cellBrush = QBrush(selectedColor);
}
//[Fill background]
painter->fillRect(itemRect, cellBrush);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question