KWindowConfig Namespace

Save and load window sizes into a config. More...

Header: #include <KWindowConfig>
CMake: find_package(KF6 REQUIRED COMPONENTS Config)
target_link_libraries(mytarget PRIVATE KF6::ConfigGui)

Functions

(since 6.0) bool hasSavedWindowPosition(KConfigGroup &config)
(since 6.0) bool hasSavedWindowSize(KConfigGroup &config)
(since 5.74) void restoreWindowPosition(QWindow *window, const KConfigGroup &config)
(since 5.99) void restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config)
(since 5.0.) void restoreWindowSize(QWindow *window, const KConfigGroup &config)
(since 5.74) void saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigBase::WriteConfigFlags options = KConfigGroup::Normal)
(since 5.0) void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigBase::WriteConfigFlags options = KConfigGroup::Normal)

Detailed Description

Function Documentation

[since 6.0] bool KWindowConfig::hasSavedWindowPosition(KConfigGroup &config)

Returns whether a given KConfig group has any saved window position data.

Note: : always returns false on Wayland where saving and restoring window position data is not supported.

config The config group to read from.

This function was introduced in 6.0.

[since 6.0] bool KWindowConfig::hasSavedWindowSize(KConfigGroup &config)

Returns whether a given KConfig group has any saved window size data.

config The config group to read from.

This function was introduced in 6.0.

[since 5.74] void KWindowConfig::restoreWindowPosition(QWindow *window, const KConfigGroup &config)

Restores the window's screen position from the configuration and calls restoreWindowScreenPosition. This function has no effect on Wayland, where the compositor is responsible for window positioning.

Note: the group must be set before calling

window The window whose position to restore.

config The config group to read from.

This function was introduced in 5.74.

[since 5.99] void KWindowConfig::restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config)

Restores the window's position on provided screen from the configuration. This function has no effect on Wayland, where the compositor is responsible for window positioning.

Note: the group must be set before calling

window The window whose position to restore.

screen Screen on which window should be placed.

config The config group to read from.

This function was introduced in 5.99.

[since 5.0.] void KWindowConfig::restoreWindowSize(QWindow *window, const KConfigGroup &config)

Restores the dialog's size from the configuration according to the screen size.

If you're calling this from a constructor (for a mainwindow or dialog, for instance) you should first call winId() so that a QWindow is created, then you can call windowHandle() to pass to this method.

Example code:

create(); // ensure there's a window created
const QSize availableSize = windowHandle()->screen()->availableSize();
windowHandle()->resize(availableSize.width() * 0.7, availableSize.height() * 0.5); // default size
KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("MyDialog"));
resize(windowHandle()->size()); // workaround for QTBUG-40584

Note: the group must be set before calling

window The window to restore size.

config The config group to read from.

This function was introduced in 5.0..

[since 5.74] void KWindowConfig::saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigBase::WriteConfigFlags options = KConfigGroup::Normal)

Saves the window's position either to the global or application config file. This function has no effect on Wayland, where the compositor is responsible for window positioning.

Note: the group must be set before calling

window The window whose position to save.

config The config group to read from.

options passed to KConfigGroup::writeEntry()

This function was introduced in 5.74.

[since 5.0] void KWindowConfig::saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigBase::WriteConfigFlags options = KConfigGroup::Normal)

Saves the window's size dependent on the screen dimension either to the global or application config file.

Note: the group must be set before calling

window The window to save size.

config The config group to read from.

options passed to KConfigGroup::writeEntry()

This function was introduced in 5.0.