How to remove this effect?
-
When I hover over the items, the top line becomes thinner or is restored to original style like this:

The code is almost same as this, I've added a
UserRolefor thoseTotal. In theDelegate, I've these:Delegate::Delegate(){ } void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); QStyledItemDelegate::paint(painter, option, index); if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){ painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } } -
When I hover over the items, the top line becomes thinner or is restored to original style like this:

The code is almost same as this, I've added a
UserRolefor thoseTotal. In theDelegate, I've these:Delegate::Delegate(){ } void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); QStyledItemDelegate::paint(painter, option, index); if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){ painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } }@Emon-Haque
your line overlaps indexes and i guess you used a (default) pen with a width of 2px.
So the half of the line is overdrawn when the index/row is repainted without the highlighting.you need to translate the line by the half of the line/pen width to ensure that it is inside the index boundaries.
-
@Emon-Haque
your line overlaps indexes and i guess you used a (default) pen with a width of 2px.
So the half of the line is overdrawn when the index/row is repainted without the highlighting.you need to translate the line by the half of the line/pen width to ensure that it is inside the index boundaries.
@raven-worx, this translation works:
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); QStyledItemDelegate::paint(painter, option, index); if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){ painter->save(); painter->translate(0,1); painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->restore(); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } }
Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?
-
@raven-worx, this translation works:
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); QStyledItemDelegate::paint(painter, option, index); if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){ painter->save(); painter->translate(0,1); painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->restore(); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } }
Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?
@Emon-Haque
just a tip:- QPainter save/restore is rather costly and should be avoided if you are after performance. Better just translate the line coordiantes
- the generic way would be to calculate the translation based on the pen width:
int translate = qCeil(painter->pen().width() * 0.5)
Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?
i dont understand your question
-
@Emon-Haque
just a tip:- QPainter save/restore is rather costly and should be avoided if you are after performance. Better just translate the line coordiantes
- the generic way would be to calculate the translation based on the pen width:
int translate = qCeil(painter->pen().width() * 0.5)
Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?
i dont understand your question
@raven-worx, the top line is now 1 px/pt below the original position so there's an extra 1px/pt gap between those top lines and last
Some Text -1,000 1000of each node, right? And all thoseTotal 1,000 1000is 1 px/pt closer to the top line. -
@raven-worx, the top line is now 1 px/pt below the original position so there's an extra 1px/pt gap between those top lines and last
Some Text -1,000 1000of each node, right? And all thoseTotal 1,000 1000is 1 px/pt closer to the top line.@Emon-Haque
i dont see an additional gap.
you may want to read this: https://doc.qt.io/qt-5/coordsys.html