From 42b5aa4acac6db0a970418ffdd400966e86ebda9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 29 Jun 2020 19:18:16 +0200 Subject: [PATCH] Target selector: Fix drawing of the run icon With the new layout calculations (see QTCREATORBUG-24148), the option rect can now be used to center the icon with the provided functions in QRect. The current code kind of works if RunColumnWidth matches the row height, so that it can do things like subtracting vertical from horizontal dimensions. But in fact, the icon is not centered on the option.rect. fillRect(option.rect, Qt::red) <-to verify. Apart from that it has a few more downsides. This change: - Uses the run icon made for dark background - Paints the icon at its native 16x16px (instead of 15x15px) - Uses QRect::center()/moveCenter() to actually center the icon Change-Id: Ib280c650bd454b551f9e30ca108579fee06d81f0 Reviewed-by: Christian Kandeler --- .../projectexplorer/miniprojecttargetselector.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/plugins/projectexplorer/miniprojecttargetselector.cpp b/src/plugins/projectexplorer/miniprojecttargetselector.cpp index c44bb43daf3..38187fd1287 100644 --- a/src/plugins/projectexplorer/miniprojecttargetselector.cpp +++ b/src/plugins/projectexplorer/miniprojecttargetselector.cpp @@ -477,14 +477,10 @@ void TargetSelectorDelegate::paint(QPainter *painter, ->setData(index, index.model()->data(index, Qt::UserRole + 1).toString(), Qt::ToolTipRole); painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText); if (index.column() == 1 && option.state & QStyle::State_MouseOver) { - const QIcon icon = Utils::Icons::RUN_SMALL.icon(); - QRect iconRect(option.rect.right() - option.rect.height(), - option.rect.top(), - option.rect.height() / painter->device()->devicePixelRatio(), - option.rect.height() / painter->device()->devicePixelRatio()); - iconRect.translate((option.rect.width() - iconRect.width()) / 2, - (option.rect.height() - iconRect.height()) / 2); - icon.paint(painter, iconRect, Qt::AlignHCenter | Qt::AlignVCenter); + const QIcon icon = Utils::Icons::RUN_SMALL_TOOLBAR.icon(); + QRect iconRect(0, 0, 16, 16); + iconRect.moveCenter(option.rect.center()); + icon.paint(painter, iconRect); } painter->restore();