6.0.0-rc4Source

QStyleHints Class

The QStyleHints class contains platform specific hints and settings. More…

Header#include <QStyleHints>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
InheritsQObject

List of all members, including inherited members

Public Functions

Signals

Detailed Description

The hints describe how the desktop wants applications to look. The application has one QStyleHints, which QGuiApplication::styleHints() returns. Its colorScheme() says whether the desktop uses a light or a dark appearance, and the default style follows it:

QApplication app(argc, argv);
if (app.styleHints()->colorScheme() == Qt::ColorScheme::Dark)
    qDebug() << "the desktop is dark";
QObject::connect(app.styleHints(), &QStyleHints::colorSchemeChanged, [](Qt::ColorScheme scheme) {
    qDebug() << "the desktop changed to" << (scheme == Qt::ColorScheme::Dark ? "dark" : "light");
});

On the xcb platform the scheme comes from the org.freedesktop.appearance color-scheme setting of the desktop portal (the "dark style" preference of GNOME, KDE and others), which is read over D-Bus when the application starts and followed as it changes.

See also QGuiApplication::styleHints() and Qt::ColorScheme.

Differences from Qt

The only hint is the color scheme. The other hints of Qt, such as the double click interval, the key repeat rate and the wheel scroll lines, are not available.

Member Function Documentation

[override] QStyleHints::~QStyleHints()

Destroys the hints.

Qt::ColorScheme QStyleHints::colorScheme() const

Returns the color scheme of the application: the one that setColorScheme() set, or else the one that the desktop reports. It is Qt::ColorScheme::Unknown if the desktop does not say.

See also setColorScheme() and unsetColorScheme().

[signal] void QStyleHints::colorSchemeChanged(Qt::ColorScheme colorScheme)

This signal is emitted when colorScheme() changes to colorScheme: the desktop switches between its light and dark appearance, or setColorScheme() is called.

void QStyleHints::setColorScheme(Qt::ColorScheme scheme)

Makes scheme the color scheme of the application, whatever the desktop says. Setting Qt::ColorScheme::Unknown is the same as calling unsetColorScheme().

See also unsetColorScheme() and colorScheme().

void QStyleHints::unsetColorScheme()

Removes the color scheme that setColorScheme() set, so that the scheme of the desktop applies again.

See also setColorScheme().