Skip to content

Commit 8c33ad7

Browse files
committed
Compatibility with older Qt 6
1 parent fe9e4ca commit 8c33ad7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

plugins/viewer/textviewer/src/ctextviewerwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ CTextViewerWindow::CTextViewerWindow(QWidget* parent) noexcept :
3333

3434
{
3535
QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
36-
const qreal sizeReatio = (qreal)QFontMetrics{qApp->font()}.height() / (qreal)QFontMetrics{fixedFont}.height();
36+
QFontMetrics fm{fixedFont};
37+
const qreal sizeReatio = fm.height() > 0 ? ((qreal)QFontMetrics{qApp->font()}.height() / (qreal)fm.height()) : 1.0;
3738
fixedFont.setPointSizeF(fixedFont.pointSizeF() * sizeReatio);
3839
_textBrowser->setFont(fixedFont);
3940
}

qt-app/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ int main(int argc, char *argv[])
4040
// Init style and color scheme, if specified
4141
{
4242
CSettings s;
43+
#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
4344
const int colorScheme = s.value(KEY_INTERFACE_COLOR_SCHEME, -1).toInt();
4445
if (colorScheme != -1)
4546
QApplication::styleHints()->setColorScheme(static_cast<Qt::ColorScheme>(colorScheme));
47+
#endif
4648

4749
const QString styleName = s.value(KEY_INTERFACE_STYLE).toString();
4850
if (!styleName.isEmpty())

qt-app/src/settings/csettingspageinterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ CSettingsPageInterface::CSettingsPageInterface(QWidget *parent) :
6767
colorSchemeGroup->addButton(ui->_rbColorSchemeLight);
6868
colorSchemeGroup->addButton(ui->_rbColorSchemeDark);
6969

70+
#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
7071
if (const auto colorScheme = QApplication::styleHints()->colorScheme(); colorScheme == Qt::ColorScheme::Dark)
7172
ui->_rbColorSchemeDark->setChecked(true);
7273
else if (colorScheme == Qt::ColorScheme::Light)
@@ -82,6 +83,7 @@ CSettingsPageInterface::CSettingsPageInterface(QWidget *parent) :
8283
_colorSchemeChanged = true;
8384
}
8485
});
86+
#endif
8587

8688
const auto settingsDialog = dynamic_cast<QDialog*>(parent);
8789
connect(settingsDialog, &QDialog::finished, this, [this] {
@@ -118,10 +120,14 @@ void CSettingsPageInterface::updateFontInfoLabel()
118120

119121
int CSettingsPageInterface::colorSchemeFromButton(QAbstractButton* btn)
120122
{
123+
#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
121124
if (btn == ui->_rbColorSchemeDark)
122125
return static_cast<int>(Qt::ColorScheme::Dark);
123126
else if (btn == ui->_rbColorSchemeLight)
124127
return static_cast<int>(Qt::ColorScheme::Light);
125128
else
126129
return static_cast<int>(Qt::ColorScheme::Unknown);
130+
#else
131+
return 0;
132+
#endif
127133
}

0 commit comments

Comments
 (0)