From 4db3209cd4e4d40c3130c4c656b79db4a8364919 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 22 Oct 2015 13:13:09 +0200 Subject: [PATCH] BinEditor: HighDPI fixes The cursor drawing caused graphical artifacts under HighDPI. Change-Id: I542346673ad8111ef03fbd80143de484fdb2d455 Task-number: QTCREATORBUG-15222 Reviewed-by: hjk --- src/plugins/bineditor/bineditor.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp index 72c7158106..920c1a75d7 100644 --- a/src/plugins/bineditor/bineditor.cpp +++ b/src/plugins/bineditor/bineditor.cpp @@ -697,6 +697,16 @@ QString BinEditorWidget::addressString(quint64 address) return m_addressString; } +static void paintCursorBorder(QPainter *painter, const QRect &cursorRect) +{ + painter->save(); + QPen borderPen(Qt::red); + borderPen.setJoinStyle(Qt::MiterJoin); + painter->setPen(borderPen); + painter->drawRect(QRectF(cursorRect).adjusted(0.5, 0.5, -0.5, -0.5)); + painter->restore(); +} + void BinEditorWidget::paintEvent(QPaintEvent *e) { QPainter painter(viewport()); @@ -869,10 +879,7 @@ void BinEditorWidget::paintEvent(QPaintEvent *e) if (cursor >= 0) { int w = fm.boundingRect(itemString.mid(cursor*3, 2)).width(); QRect cursorRect(x + cursor * m_columnWidth, y - m_ascent, w + 1, m_lineHeight); - painter.save(); - painter.setPen(Qt::red); - painter.drawRect(cursorRect.adjusted(0, 0, 0, -1)); - painter.restore(); + paintCursorBorder(&painter, cursorRect); if (m_hexCursor && m_cursorVisible) { if (m_lowNibble) cursorRect.adjust(fm.width(itemString.left(1)), 0, 0, 0); @@ -911,17 +918,16 @@ void BinEditorWidget::paintEvent(QPaintEvent *e) y-m_ascent, fm.width(printable.at(cursor)), m_lineHeight); - painter.save(); if (m_hexCursor || !m_cursorVisible) { - painter.setPen(Qt::red); - painter.drawRect(cursorRect.adjusted(0, 0, 0, -1)); + paintCursorBorder(&painter, cursorRect); } else { + painter.save(); painter.setClipRect(cursorRect); painter.fillRect(cursorRect, Qt::red); painter.setPen(Qt::white); painter.drawText(text_x, y, printable); + painter.restore(); } - painter.restore(); } } } -- GitLab