Skip to content

Commit 4dedbba

Browse files
authored
Merge pull request sqlitebrowser#3162 from hikmet517/master
Update line number width when zooming. Calculating number width using `font()` does not take zoom into account. So, the overload of `setMarginWidth` with `QString` as second parameter was used. This way we leave the width calculation to QScintilla which considers the zoom while calculating.
2 parents 16cea35 + ff8b846 commit 4dedbba

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/ExtendedScintilla.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ExtendedScintilla::ExtendedScintilla(QWidget* parent) :
5757

5858
// Connect signals
5959
connect(this, &ExtendedScintilla::linesChanged, this, &ExtendedScintilla::updateLineNumberAreaWidth);
60+
connect(this, &QsciScintillaBase::SCN_ZOOM, this, &ExtendedScintilla::updateLineNumberAreaWidth);
6061

6162
// The shortcuts are constrained to the Widget context so they do not conflict with other SqlTextEdit widgets in the Main Window.
6263
QShortcut* shortcutFindReplace = new QShortcut(QKeySequence(tr("Ctrl+H")), this, nullptr, nullptr, Qt::WidgetShortcut);
@@ -89,11 +90,7 @@ void ExtendedScintilla::updateLineNumberAreaWidth()
8990

9091
// Calculate the width of this number if it was all zeros (this is because a 1 might require less space than a 0 and this could
9192
// cause some flickering depending on the font) and set the new margin width.
92-
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
93-
setMarginWidth(0, QFontMetrics(font()).width(QString("0").repeated(digits)) + 5);
94-
#else
95-
setMarginWidth(0, QFontMetrics(font()).horizontalAdvance(QString("0").repeated(digits)) + 5);
96-
#endif
93+
setMarginWidth(0, QString("0").repeated(digits+1));
9794
}
9895

9996
void ExtendedScintilla::dropEvent(QDropEvent* e)

0 commit comments

Comments
 (0)