forked from osmocom/wireshark
QT ByteViewText: calculate string widths consistently to prevent clipping
For QT >5.11, stringWidth() uses horizontalAdvance, which gives different (longer) widths than the old boundingRect().width() method. Other locations use the boundRect().width() method directly, resulting in underestimating line widths and clipping the last characters in the byte view window. Fix by forcing all width calculations to use stringWidth(). Closes #17087.
This commit is contained in:
parent
cd77e5aa5f
commit
95f3d1b075
|
@ -344,7 +344,7 @@ const int ByteViewText::separator_interval_ = DataPrinter::separatorInterval();
|
||||||
|
|
||||||
void ByteViewText::updateLayoutMetrics()
|
void ByteViewText::updateLayoutMetrics()
|
||||||
{
|
{
|
||||||
font_width_ = fontMetrics().boundingRect('M').width();
|
font_width_ = stringWidth("M");
|
||||||
// We might want to match ProtoTree::rowHeight.
|
// We might want to match ProtoTree::rowHeight.
|
||||||
line_height_ = fontMetrics().height();
|
line_height_ = fontMetrics().height();
|
||||||
}
|
}
|
||||||
|
@ -607,7 +607,7 @@ int ByteViewText::offsetPixels()
|
||||||
if (show_offset_) {
|
if (show_offset_) {
|
||||||
// One pad space before and after
|
// One pad space before and after
|
||||||
QString zeroes = QString(offsetChars(), '0');
|
QString zeroes = QString(offsetChars(), '0');
|
||||||
return fontMetrics().boundingRect(zeroes).width();
|
return stringWidth(zeroes);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -618,7 +618,7 @@ int ByteViewText::hexPixels()
|
||||||
if (show_hex_) {
|
if (show_hex_) {
|
||||||
// One pad space before and after
|
// One pad space before and after
|
||||||
QString zeroes = QString(DataPrinter::hexChars() + 2, '0');
|
QString zeroes = QString(DataPrinter::hexChars() + 2, '0');
|
||||||
return fontMetrics().boundingRect(zeroes).width();
|
return stringWidth(zeroes);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ int ByteViewText::asciiPixels()
|
||||||
// Two pad spaces before, one after
|
// Two pad spaces before, one after
|
||||||
int ascii_chars = (row_width_ + ((row_width_ - 1) / separator_interval_));
|
int ascii_chars = (row_width_ + ((row_width_ - 1) / separator_interval_));
|
||||||
QString zeroes = QString(ascii_chars + 3, '0');
|
QString zeroes = QString(ascii_chars + 3, '0');
|
||||||
return fontMetrics().boundingRect(zeroes).width();
|
return stringWidth(zeroes);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue