update line number width while zooming

This commit is contained in:
Hikmet Altıntaş
2022-09-01 15:06:24 +03:00
parent a78dd0292f
commit ff8b846c04

View File

@@ -57,6 +57,7 @@ ExtendedScintilla::ExtendedScintilla(QWidget* parent) :
// Connect signals
connect(this, &ExtendedScintilla::linesChanged, this, &ExtendedScintilla::updateLineNumberAreaWidth);
connect(this, &QsciScintillaBase::SCN_ZOOM, this, &ExtendedScintilla::updateLineNumberAreaWidth);
// The shortcuts are constrained to the Widget context so they do not conflict with other SqlTextEdit widgets in the Main Window.
QShortcut* shortcutFindReplace = new QShortcut(QKeySequence(tr("Ctrl+H")), this, nullptr, nullptr, Qt::WidgetShortcut);
@@ -89,11 +90,7 @@ void ExtendedScintilla::updateLineNumberAreaWidth()
// 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
// cause some flickering depending on the font) and set the new margin width.
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setMarginWidth(0, QFontMetrics(font()).width(QString("0").repeated(digits)) + 5);
#else
setMarginWidth(0, QFontMetrics(font()).horizontalAdvance(QString("0").repeated(digits)) + 5);
#endif
setMarginWidth(0, QString("0").repeated(digits+1));
}
void ExtendedScintilla::dropEvent(QDropEvent* e)