fix vertical scroll

used the wrong font height
This commit is contained in:
2021-10-25 10:00:26 +02:00
parent 905fe355e5
commit 424f4bb11d
2 changed files with 30 additions and 7 deletions

View File

@@ -140,12 +140,16 @@ class InnerBigText(QWidget):
painter.setPen(QColor(0, 0, 0))
self.update_font_metrics(painter)
lines_to_show = self.height() / (self.fontMetrics().height())
lines_to_show = self.height() / float(self.char_height)
#print("%s / %s = %s" %(self.height(), float(self.char_height), lines_to_show))
self.lines = self.model.data(self._byte_offset, self.scroll_lines, lines_to_show)
#print("lines_to_show: %d returned: %d" % (lines_to_show, len(self.lines)))
self.scroll_lines=0
self._byte_offset = self.lines[0].byte_offset()
self.parent.v_scroll_bar.setMaximum(
self.model.byte_count() - 1 - 10) # document length == maximum + pageStep + aFewBytesSoThatTheLastLineIsShown
# document length == maximum + pageStep + aFewBytesSoThatTheLastLineIsShown
self.parent.v_scroll_bar.setMaximum(self.model.byte_count() - 1 - 10)
for l in self.lines:
self.update_longest_line(len(l.line()))
@@ -198,8 +202,7 @@ class InnerBigText(QWidget):
def update_font_metrics(self, painter: QPainter):
fm: QFontMetrics = painter.fontMetrics()
self.char_height = fm.height()
self.char_width = fm.averageCharWidth() # all chars have same with for monospace font
self.char_width = fm.averageCharWidth() # all chars have same width for monospace font
text = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
self.char_width = fm.horizontalAdvance(text) / float(len(text))
# print("bounding rect: %s"%(boundingRect))
# print("font width=%s height=%s" % (self.char_width, self.char_height))
#print("font width=%s height=%s" % (self.char_width, self.char_height))