Skip to content

Commit

Permalink
fix: Avoid infinite repaints upon hovering the folders/tags panels
Browse files Browse the repository at this point in the history
We were calling setStyleSheet() unconditionally inside the paint event
handlers of the folders/tags panels, which would then trigger a new
paint event, causing an infinite repaint recursion.

Now, we only call setStylesheet() if the stylesheet of a widget actually
needs to be updated.

(cherry picked from commit 9cb2616)
  • Loading branch information
guihkx committed Oct 25, 2024
1 parent 75bd647 commit ec83d0b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
46 changes: 30 additions & 16 deletions src/foldertreedelegateeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,50 @@ void FolderTreeDelegateEditor::updateDelegate()
auto displayName = m_index.data(NodeItem::Roles::DisplayText).toString();
QFontMetrics fm(m_titleFont);
displayName = fm.elidedText(displayName, Qt::ElideRight, m_label->contentsRect().width());
QString labelStyle;
QString folderIconStyle;

if (m_view->selectionModel()->isSelected(m_index)) {
m_label->setStyleSheet(QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleSelectedColor.red()),
QString::number(m_titleSelectedColor.green()),
QString::number(m_titleSelectedColor.blue())));
m_folderIcon->setStyleSheet(
labelStyle = QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleSelectedColor.red()),
QString::number(m_titleSelectedColor.green()),
QString::number(m_titleSelectedColor.blue()));
folderIconStyle =
QStringLiteral("QPushButton{border: none; padding: 0px; color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleSelectedColor.red()),
QString::number(m_titleSelectedColor.green()),
QString::number(m_titleSelectedColor.blue())));
QString::number(m_titleSelectedColor.blue()));
} else {
m_label->setStyleSheet(QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleColor.red()),
QString::number(m_titleColor.green()),
QString::number(m_titleColor.blue())));
m_folderIcon->setStyleSheet(
labelStyle = QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleColor.red()),
QString::number(m_titleColor.green()),
QString::number(m_titleColor.blue()));
folderIconStyle =
QStringLiteral("QPushButton{border: none; padding: 0px; color: rgb(%1, %2, %3);}")
.arg(QString::number(m_folderIconColor.red()),
QString::number(m_folderIconColor.green()),
QString::number(m_folderIconColor.blue())));
QString::number(m_folderIconColor.blue()));
}
m_label->setText(displayName);
auto theme = dynamic_cast<NodeTreeView *>(m_view)->theme();

QColor chevronColor(theme == Theme::Dark ? QColor(169, 160, 172) : QColor(103, 99, 105));
m_expandIcon->setStyleSheet(QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(chevronColor.red()),
QString::number(chevronColor.green()),
QString::number(chevronColor.blue())));
QString expandIconStyle =
QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(chevronColor.red()), QString::number(chevronColor.green()),
QString::number(chevronColor.blue()));

if (m_folderIcon->styleSheet() != folderIconStyle) {
m_folderIcon->setStyleSheet(folderIconStyle);
}

if (m_label->styleSheet() != labelStyle) {
m_label->setStyleSheet(labelStyle);
}

if (m_expandIcon->styleSheet() != expandIconStyle) {
m_expandIcon->setStyleSheet(expandIconStyle);
}

if (m_index.data(NodeItem::Roles::IsExpandable).toBool()) {
if (m_view->isExpanded(m_index)) {
Expand Down
21 changes: 13 additions & 8 deletions src/tagtreedelegateeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,24 @@ void TagTreeDelegateEditor::updateDelegate()
auto displayName = m_index.data(NodeItem::Roles::DisplayText).toString();
QFontMetrics fm(m_titleFont);
displayName = fm.elidedText(displayName, Qt::ElideRight, m_label->contentsRect().width());
QString labelStyle;

if (m_view->selectionModel()->selectedIndexes().contains(m_index)) {
m_label->setStyleSheet(QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleSelectedColor.red()),
QString::number(m_titleSelectedColor.green()),
QString::number(m_titleSelectedColor.blue())));
labelStyle = QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleSelectedColor.red()),
QString::number(m_titleSelectedColor.green()),
QString::number(m_titleSelectedColor.blue()));
} else {
m_label->setStyleSheet(QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleColor.red()),
QString::number(m_titleColor.green()),
QString::number(m_titleColor.blue())));
labelStyle = QStringLiteral("QLabel{color: rgb(%1, %2, %3);}")
.arg(QString::number(m_titleColor.red()),
QString::number(m_titleColor.green()),
QString::number(m_titleColor.blue()));
}
m_label->setText(displayName);

if (m_label->styleSheet() != labelStyle) {
m_label->setStyleSheet(labelStyle);
}
}

void TagTreeDelegateEditor::paintEvent(QPaintEvent *event)
Expand Down

0 comments on commit ec83d0b

Please sign in to comment.