diff --git a/src/main.cpp b/src/main.cpp index a3220778..e9c19fd1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -17,8 +19,8 @@ #include #include #include -#include #include +#include #include #include "commandlineoptions.h" #include "application.h" @@ -145,17 +147,8 @@ int main(int argc, char *argv[]) // Should set the correct locale before VNoteX::getInst(). loadTranslators(app); - if (app.styleSheet().isEmpty()) { - auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet(); - if (!style.isEmpty()) { - app.setStyleSheet(style); - } - } - MainWindow window; - window.show(); - VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base)); QObject::connect(&guard, &SingleInstanceGuard::showRequested, &window, &MainWindow::showMainWindow); @@ -167,6 +160,19 @@ int main(int argc, char *argv[]) window.openFiles(QStringList() << p_filePath); }); + // Let MainWindow show first to decide the screen on which app is running. + WidgetUtils::calculateScaleFactor(window.windowHandle()->screen()); + + if (app.styleSheet().isEmpty()) { + auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet(); + if (!style.isEmpty()) { + app.setStyleSheet(style); + WidgetUtils::updateStyle(&window); + } + } + + VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base)); + window.kickOffOnStart(cmdOptions.m_pathsToOpen); int ret = app.exec(); diff --git a/src/utils/widgetutils.cpp b/src/utils/widgetutils.cpp index 9ea4a6bb..9c97d661 100644 --- a/src/utils/widgetutils.cpp +++ b/src/utils/widgetutils.cpp @@ -45,12 +45,14 @@ void WidgetUtils::updateStyle(QWidget *p_widget) p_widget->update(); } -qreal WidgetUtils::calculateScaleFactor(bool p_update) +qreal WidgetUtils::calculateScaleFactor(const QScreen *p_screen) { static qreal factor = -1; - if (factor < 0 || p_update) { - factor = QGuiApplication::primaryScreen()->devicePixelRatio(); + if (factor < 0 || p_screen) { + auto screen = p_screen ? p_screen : QGuiApplication::primaryScreen(); + factor = screen->devicePixelRatio(); + qDebug() << screen->name() << "dpi" << factor; } return factor; diff --git a/src/utils/widgetutils.h b/src/utils/widgetutils.h index 797c141a..53db0761 100644 --- a/src/utils/widgetutils.h +++ b/src/utils/widgetutils.h @@ -21,6 +21,7 @@ class QLineEdit; class QLayout; class QPushButton; class QSplitter; +class QScreen; namespace vnotex { @@ -35,7 +36,7 @@ namespace vnotex static void updateStyle(QWidget *p_widget); - static qreal calculateScaleFactor(bool p_update = false); + static qreal calculateScaleFactor(const QScreen *p_screen = nullptr); static bool isScrollBarVisible(QAbstractScrollArea *p_widget, bool p_horizontal);