An open API service indexing awesome lists of open source software.

https://github.com/mguludag/qstylehelper

A Helper class for managing QStyle, QPalette, TitleBar Color on Windows and auto detect color scheme changes.
https://github.com/mguludag/qstylehelper

acrylic linux mica qml qstyle qt qt5-gui qtwidgets windows windows-10 windows-11 winui

Last synced: 2 months ago
JSON representation

A Helper class for managing QStyle, QPalette, TitleBar Color on Windows and auto detect color scheme changes.

Awesome Lists containing this project

README

        

# QStyleHelper
A Helper class for managing QStyle, QPalette, TitleBar Color on Windows and auto detect color scheme changes.

## Features
* Auto dark mode app style, titlebar and titlebar context menu on windows
* Supports Mica style on Windows 11 (you have to set background transparent)
* Supports Acrylic Transparent Blur on Windows 10/11 (you have to set background transparent)
* Setting your custom dark/light palette
* Provide signal for system dark/light scheme changes (useful for changing your app icons)

https://user-images.githubusercontent.com/12413639/216264921-933c2670-b1d5-4b67-8624-c5c8aaf39ecd.mp4

https://user-images.githubusercontent.com/12413639/216384897-b8f63c3a-2658-4637-acaa-d85e74e75869.mp4

## Usage for Qt Widgets
### main.cpp
```C++
#include "mainwindow.h"
#include "qstylehelper.hpp"
#include

int main(int argc, char *argv[])
{
// this function uses new Qt >= 5.15 win32 dark titlebar environment
QStyleHelper::setTitleBarDarkColor();

QApplication a(argc, argv);
MainWindow w;

// if you want to use Mica or Acrylic Blur you have to set background transparent
w.setAttribute(Qt::WA_TranslucentBackground);

// this is for Windows 11
// example use of Mica, second bool parameter is setting acrylic transparent for mica
QStyleHelper::setMica({w});

// this is for Windows 10/11 but resize performance is slow (deprecated)
// example use of Acrylic Blur Window, second bool parameter is setting acrylic transparent for it
QStyleHelper::setAcrylicBlurWindow({w}, true);


// if your Qt version older than 5.15 use it like this for win32 dark titlebar environment and also you have to call once for any subwindows
QStyleHelper::setTitleBarDarkColor({w});

// initialize the instance and set desired look you want, also you can set any custom QPalette for dark and light scheme separately
QStyleHelper::instance().setDarkPalette().setWidgetStyle("fusion").setAutoChangePalette(true);

// this connection and QStyleHelper::colorSchemeChanged signal for monitor windows dark/light mode changes
QObject::connect(&QStyleHelper::instance(), &QStyleHelper::colorSchemeChanged, [&w](bool dark)
{ QStyleHelper::setMica({w}); QStyleHelper::setTitleBarDarkColor({w}, dark); });

w.show();

return a.exec();
}
```

## Usage for Qt Quick
### main.cpp
```C++
#include
#include
#include "qstylehelper.hpp"

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);

// if your Qt version older than 5.15 use it like this for win32 dark titlebar environment
QStyleHelper::setTitleBarDarkColor(QGuiApplication::allWindows());

// this is for Windows 11
// example use of Mica, second bool parameter is setting acrylic transparent for mica
QStyleHelper::setMica(QGuiApplication::allWindows(), true);

// this is for Windows 10/11 but resize performance is slow (deprecated)
// example use of Acrylic Blur Window, second bool parameter is setting acrylic transparent for it
QStyleHelper::setAcrylicBlurWindow(QGuiApplication::allWindows());

// this connection and QStyleHelper::colorSchemeChanged signal for monitor windows dark/light mode changes
QObject::connect(&QStyleHelper::instance(), &QStyleHelper::colorSchemeChanged, [](bool b)
{ QStyleHelper::setMica(QGuiApplication::allWindows(), true); QStyleHelper::setTitleBarDarkColor(QGuiApplication::allWindows(), b); });

return app.exec();
}
}
```