1
0

feat: change application style

- change default dark theme to light
- disable dark mode on windows 10 because Qt's windows 11 theme has bad support on windows 10 (icon display error)
- level required minimum qt version up to 6.5 for color schema.
This commit is contained in:
2026-07-08 20:15:22 +08:00
parent c06f900ac5
commit 46f46480cb
10 changed files with 139 additions and 33 deletions

View File

@@ -20,7 +20,7 @@ set (CMAKE_AUTOUIC ON)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
set (QT_MINIMUM_VERSION "6.4") set (QT_MINIMUM_VERSION "6.5")
find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED
COMPONENTS Widgets Svg SvgWidgets LinguistTools COMPONENTS Widgets Svg SvgWidgets LinguistTools

View File

@@ -15,35 +15,25 @@ BottomButtonGroup::BottomButtonGroup(const std::vector<QAction *> &actionList, Q
mainLayout->setSizeConstraint(QLayout::SetFixedSize); mainLayout->setSizeConstraint(QLayout::SetFixedSize);
this->setLayout(mainLayout); this->setLayout(mainLayout);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->setStyleSheet("BottomButtonGroup {" this->setStyleSheet(R"#(
"border: 1px solid gray;" BottomButtonGroup {
"border-top-left-radius: 10px;" border-style: none;
"border-top-right-radius: 10px;" background: transparent;
"border-style: none;" }
"background-color:rgba(0,0,0,120)" QToolButton {
"}" background: transparent;
"QToolButton {" border-style: none;
"background:transparent;" }
"}" )#");
"QToolButton:!focus {"
"border-style: none;"
"}");
auto newActionBtn = [this](QAction * action) -> QToolButton * { for (QAction * action : actionList) {
// Create button
QToolButton * btn = new QToolButton(this); QToolButton * btn = new QToolButton(this);
btn->setDefaultAction(action); btn->setDefaultAction(action);
btn->setIconSize(QSize(32, 32)); btn->setIconSize(QSize(32, 32));
btn->setFixedSize(40, 40); btn->setFixedSize(40, 40);
return btn; // Add button
}; layout()->addWidget(btn);
for (QAction * action : actionList) {
addButton(newActionBtn(action));
} }
}
void BottomButtonGroup::addButton(QAbstractButton *button)
{
layout()->addWidget(button);
updateGeometry(); updateGeometry();
} }

View File

@@ -15,8 +15,6 @@ class BottomButtonGroup : public QGroupBox
Q_OBJECT Q_OBJECT
public: public:
explicit BottomButtonGroup(const std::vector<QAction *> & actionList, QWidget *parent = nullptr); explicit BottomButtonGroup(const std::vector<QAction *> & actionList, QWidget *parent = nullptr);
void addButton(QAbstractButton *button);
}; };
#endif // BOTTOMBUTTONGROUP_H #endif // BOTTOMBUTTONGROUP_H

View File

@@ -6,6 +6,9 @@
#include "settings.h" #include "settings.h"
#include <QStyleHints>
#include <QOperatingSystemVersion>
#include <QGuiApplication>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QMimeData> #include <QMimeData>
#include <QDebug> #include <QDebug>
@@ -16,6 +19,33 @@
#include <QMovie> #include <QMovie>
#include <QPainter> #include <QPainter>
static const QColor& ColorSchemaToTextForeground(Qt::ColorScheme colorScheme) {
// YYC MARK:
// If we are using Windows 10 and lower system or Qt which do not support "Windows 11"
// theme (lower than Qt 6.7), we should only support light mode.
// Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11.
#if defined(Q_OS_WIN)
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
colorScheme = Qt::ColorScheme::Light;
#else
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) {
colorScheme = Qt::ColorScheme::Light;
}
#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
#endif // defined(Q_OS_WIN)
switch (colorScheme) {
case Qt::ColorScheme::Dark:
static QColor WHITE = QColor("White");
return WHITE;
case Qt::ColorScheme::Light:
case Qt::ColorScheme::Unknown:
default:
static QColor BLACK = QColor("Black");
return BLACK;
}
}
class PGraphicsPixmapItem : public QGraphicsPixmapItem class PGraphicsPixmapItem : public QGraphicsPixmapItem
{ {
public: public:
@@ -100,6 +130,7 @@ GraphicsScene::GraphicsScene(QObject *parent)
: QGraphicsScene(parent) : QGraphicsScene(parent)
{ {
showText(tr("Drag image here")); showText(tr("Drag image here"));
connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &GraphicsScene::updateStyle);
} }
GraphicsScene::~GraphicsScene() GraphicsScene::~GraphicsScene()
@@ -121,7 +152,7 @@ void GraphicsScene::showText(const QString &text)
{ {
this->clear(); this->clear();
QGraphicsTextItem * textItem = this->addText(text); QGraphicsTextItem * textItem = this->addText(text);
textItem->setDefaultTextColor(QColor("White")); textItem->setDefaultTextColor(ColorSchemaToTextForeground(qGuiApp->styleHints()->colorScheme()));
m_theThing = textItem; m_theThing = textItem;
this->setSceneRect(m_theThing->boundingRect()); this->setSceneRect(m_theThing->boundingRect());
} }
@@ -206,3 +237,14 @@ QPixmap GraphicsScene::renderToPixmap()
return pixmap; return pixmap;
} }
void GraphicsScene::updateStyle(Qt::ColorScheme colorScheme) {
Q_UNUSED(colorScheme)
QGraphicsItem * item = this->m_theThing;
if (item == nullptr) return;
QGraphicsTextItem * textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
if (textItem == nullptr) return;
textItem->setDefaultTextColor(ColorSchemaToTextForeground(colorScheme));
}

View File

@@ -26,6 +26,9 @@ public:
QPixmap renderToPixmap(); QPixmap renderToPixmap();
public slots:
void updateStyle(Qt::ColorScheme colorScheme);
private: private:
QGraphicsItem * m_theThing = nullptr; QGraphicsItem * m_theThing = nullptr;
}; };

View File

@@ -7,6 +7,8 @@
#include "graphicsscene.h" #include "graphicsscene.h"
#include "settings.h" #include "settings.h"
#include <QStyleHints>
#include <QOperatingSystemVersion>
#include <QDebug> #include <QDebug>
#include <QColorSpace> #include <QColorSpace>
#include <QMouseEvent> #include <QMouseEvent>
@@ -23,11 +25,12 @@ GraphicsView::GraphicsView(QWidget *parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setResizeAnchor(QGraphicsView::AnchorUnderMouse); setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setStyleSheet("background-color: rgba(0, 0, 0, 220);"
"border-radius: 3px;");
setAcceptDrops(false); setAcceptDrops(false);
setCheckerboardEnabled(false); setCheckerboardEnabled(false);
updateStyle(qGuiApp->styleHints()->colorScheme());
connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &GraphicsView::updateStyle);
connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
} }
@@ -344,6 +347,39 @@ void GraphicsView::toggleCheckerboard(bool invertCheckerboardColor)
setCheckerboardEnabled(!m_checkerboardEnabled, invertCheckerboardColor); setCheckerboardEnabled(!m_checkerboardEnabled, invertCheckerboardColor);
} }
void GraphicsView::updateStyle(Qt::ColorScheme colorScheme) {
// YYC MARK:
// If we are using Windows 10 and lower system or Qt which do not support "Windows 11"
// theme (lower than Qt 6.7), we should only support light mode.
// Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11.
#if defined(Q_OS_WIN)
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
colorScheme = Qt::ColorScheme::Light;
#else
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) {
colorScheme = Qt::ColorScheme::Light;
}
#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
#endif // defined(Q_OS_WIN)
switch (colorScheme) {
case Qt::ColorScheme::Dark:
setStyleSheet(R"#(
border-style: none;
background-color: black;
)#");
break;
case Qt::ColorScheme::Light:
case Qt::ColorScheme::Unknown:
default:
setStyleSheet(R"#(
border-style: none;
background-color: white;
)#");
break;
}
}
void GraphicsView::mousePressEvent(QMouseEvent *event) void GraphicsView::mousePressEvent(QMouseEvent *event)
{ {
if (shouldIgnoreMousePressMoveEvent(event)) { if (shouldIgnoreMousePressMoveEvent(event)) {

View File

@@ -51,6 +51,7 @@ signals:
public slots: public slots:
void toggleCheckerboard(bool invertCheckerboardColor = false); void toggleCheckerboard(bool invertCheckerboardColor = false);
void updateStyle(Qt::ColorScheme colorScheme);
private: private:
void mousePressEvent(QMouseEvent * event) override; void mousePressEvent(QMouseEvent * event) override;

View File

@@ -51,7 +51,6 @@ MainWindow::MainWindow(QWidget *parent)
, m_pm(new PlaylistManager(this)) , m_pm(new PlaylistManager(this))
, m_fileSystemWatcher(new QFileSystemWatcher(this)) , m_fileSystemWatcher(new QFileSystemWatcher(this))
{ {
this->setAttribute(Qt::WA_TranslucentBackground, true);
// YYC MARK: // YYC MARK:
// Blumis set original value is 350 x 330. // Blumis set original value is 350 x 330.
// It is too small for modern device, // It is too small for modern device,

View File

@@ -6,6 +6,8 @@
#include "graphicsview.h" #include "graphicsview.h"
#include <QStyleHints>
#include <QOperatingSystemVersion>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
@@ -16,8 +18,9 @@ NavigatorView::NavigatorView(QWidget *parent)
{ {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("background-color: rgba(0, 0, 0, 120);"
"border-radius: 3px;"); updateStyle(qGuiApp->styleHints()->colorScheme());
connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &NavigatorView::updateStyle);
} }
// doesn't take or manage its ownership // doesn't take or manage its ownership
@@ -38,6 +41,39 @@ void NavigatorView::updateMainViewportRegion()
}); });
} }
void NavigatorView::updateStyle(Qt::ColorScheme colorScheme) {
// YYC MARK:
// If we are using Windows 10 and lower system or Qt which do not support "Windows 11"
// theme (lower than Qt 6.7), we should only support light mode.
// Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11.
#if defined(Q_OS_WIN)
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
colorScheme = Qt::ColorScheme::Light;
#else
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) {
colorScheme = Qt::ColorScheme::Light;
}
#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
#endif // defined(Q_OS_WIN)
switch (colorScheme) {
case Qt::ColorScheme::Dark:
setStyleSheet(R"#(
border-style: none;
background-color: rgba(255, 255, 255, 70);
)#");
break;
case Qt::ColorScheme::Light:
case Qt::ColorScheme::Unknown:
default:
setStyleSheet(R"#(
border-style: none;
background-color: rgba(0, 0, 0, 70);
)#");
break;
}
}
void NavigatorView::mousePressEvent(QMouseEvent *event) void NavigatorView::mousePressEvent(QMouseEvent *event)
{ {
m_mouseDown = true; m_mouseDown = true;

View File

@@ -18,6 +18,7 @@ public:
public slots: public slots:
void updateMainViewportRegion(); void updateMainViewportRegion();
void updateStyle(Qt::ColorScheme colorScheme);
private: private:
void mousePressEvent(QMouseEvent * event) override; void mousePressEvent(QMouseEvent * event) override;