From 0d59da3156f834986444bb0cec22ae810b19d36b Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 18 Oct 2022 12:38:36 -0700 Subject: [PATCH] Qt: Fix the ByteViewText line height. QFontMetrics::leading() was zero for Consolas on Windows in Qt5, but is nonzero in Qt6. This revealed that we were inconsistently using height() and leading() to calculate our line height. Just use lineSpacing() instead. Fixes #18438. --- ui/qt/widgets/byte_view_text.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp index d511870ffc..543ebb82d4 100644 --- a/ui/qt/widgets/byte_view_text.cpp +++ b/ui/qt/widgets/byte_view_text.cpp @@ -32,9 +32,12 @@ // - Add recent settings and context menu items to show/hide the offset. // - Add a UTF-8 and possibly UTF-xx option to the ASCII display. // - Move more common metrics to DataPrinter. + +// Alternative implementations: // - Pre-draw all of our characters and paint our display using pixmap // copying? That would make this behave like a terminal screen, which // is what we ultimately want. +// - Use QGraphicsView + QGraphicsScene + QGraphicsTextItem instead? Q_DECLARE_METATYPE(bytes_view_type) Q_DECLARE_METATYPE(bytes_encoding_type) @@ -250,14 +253,13 @@ void ByteViewText::paintEvent(QPaintEvent *) // Data rows int widget_height = height(); - int leading = fontMetrics().leading(); painter.save(); x_pos_to_column_.clear(); while ((int) (row_y + line_height_) < widget_height && offset < (int) data_.size()) { drawLine(&painter, offset, row_y); offset += row_width_; - row_y += line_height_ + leading; + row_y += line_height_; } painter.restore(); @@ -364,7 +366,7 @@ void ByteViewText::updateLayoutMetrics() { font_width_ = stringWidth("M"); // We might want to match ProtoTree::rowHeight. - line_height_ = fontMetrics().height(); + line_height_ = fontMetrics().lineSpacing(); } int ByteViewText::stringWidth(const QString &line)