### Build and Install QWindowKit using CMake (Bash) Source: https://context7.com/stdware/qwindowkit/llms.txt This bash script outlines the process for cloning the QWindowKit repository, configuring the build with CMake, compiling, and installing it. It specifies Qt's installation path, build components (Widgets, Quick), and installation prefix. This prepares QWindowKit for use in other projects. ```bash # Build and install QWindowKit git clone --recursive https://github.com/stdware/qwindowkit cd qwindowkit cmake -B build -S . \ -DCMAKE_PREFIX_PATH=/path/to/Qt/6.6.2/gcc_64 \ -DQWINDOWKIT_BUILD_WIDGETS=ON \ -DQWINDOWKIT_BUILD_QUICK=ON \ -DQWINDOWKIT_BUILD_EXAMPLES=OFF \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DCMAKE_BUILD_TYPE=Release cmake --build build --parallel cmake --install build # Use installed QWindowKit in your project cmake -B build -S . \ -DCMAKE_PREFIX_PATH="/path/to/Qt/6.6.2/gcc_64;/usr/local" \ -DQWindowKit_DIR=/usr/local/lib/cmake/QWindowKit cmake --build build ``` -------------------------------- ### Integrate QWindowKit with CMake Source: https://context7.com/stdware/qwindowkit/llms.txt This CMake configuration shows how to find and link QWindowKit components (Core, Widgets, Quick) into your application. It provides examples for both linking against an installed QWindowKit and building QWindowKit from source as a subdirectory. Ensure QWindowKit is correctly installed or the source directory is available. ```cmake # Find QWindowKit package find_package(QWindowKit COMPONENTS Core Widgets Quick REQUIRED) # Link Qt Widgets application add_executable(MyWidgetsApp main.cpp mainwindow.cpp) target_link_libraries(MyWidgetsApp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets QWindowKit::Widgets ) # Link Qt Quick application add_executable(MyQuickApp main.cpp) target_link_libraries(MyQuickApp PRIVATE Qt${QT_VERSION_MAJOR}::Quick QWindowKit::Quick ) # Build QWindowKit from source as subdirectory set(QWINDOWKIT_BUILD_WIDGETS ON CACHE BOOL "") set(QWINDOWKIT_BUILD_QUICK ON CACHE BOOL "") set(QWINDOWKIT_BUILD_EXAMPLES OFF CACHE BOOL "") add_subdirectory(qwindowkit) target_link_libraries(MyApp PRIVATE QWindowKit::Widgets) ``` -------------------------------- ### Qt Quick Window Setup with QWindowKit Source: https://github.com/stdware/qwindowkit/blob/main/README.md This QML code demonstrates the basic setup of a Qt Quick Window using QWindowKit. It imports the necessary modules, initializes the WindowAgent, and makes the window visible after setup. The output is a visible QML Window managed by QWindowKit. ```qml import QtQuick 2.15 import QtQuick.Window 2.15 import QWindowKit 1.0 Window { id: window visible: false // We hide it first, so we can move the window to our desired position silently. Component.onCompleted: { windowAgent.setup(window) window.visible = true } WindowAgent { id: windowAgent // ... } ``` -------------------------------- ### Build and Install QWindowKit with CMake Source: https://github.com/stdware/qwindowkit/blob/main/README.md This code snippet demonstrates how to clone the QWindowKit repository, navigate into the directory, and configure the build using CMake with various options such as specifying Qt installation path, enabling Quick module, setting installation prefix, and choosing a generator. It also shows how to build and install the project for both Debug and Release configurations. ```sh git clone --recursive https://github.com/stdware/qwindowkit cd qwindowkit cmake -B build -S . \ -DCMAKE_PREFIX_PATH= \ -Dqmsetup_DIR= \ -DQWINDOWKIT_BUILD_QUICK=TRUE \ -DCMAKE_INSTALL_PREFIX=/path/install \ -G "Ninja Multi-Config" cmake --build build --target install --config Debug cmake --build build --target install --config Release ``` -------------------------------- ### Install QWindowKit CMake Configuration Files (CMake) Source: https://github.com/stdware/qwindowkit/blob/main/src/CMakeLists.txt This snippet handles the installation of QWindowKit's CMake configuration files. It uses `qm_basic_install` to define the installation directory, version, configuration template, namespace, and export targets. It also includes a mechanism for installing shared files by including another CMake script. ```cmake if(QWINDOWKIT_INSTALL) qm_basic_install( NAME ${QWINDOWKIT_INSTALL_NAME} VERSION ${QWINDOWKIT_VERSION} INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${QWINDOWKIT_INSTALL_NAME} CONFIG_TEMPLATE "${QWINDOWKIT_INSTALL_NAME}Config.cmake.in" NAMESPACE ${QWINDOWKIT_INSTALL_NAME}:: EXPORT ${QWINDOWKIT_INSTALL_NAME}Targets WRITE_CONFIG_OPTIONS NO_CHECK_REQUIRED_COMPONENTS_MACRO ) # Install shared files include("../share/install.cmake") endif() ``` -------------------------------- ### QWindowKit Application Initialization Setup (C++) Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code outlines the critical setup required before creating any widgets in a QWindowKit application. It includes setting the Qt::AA_DontCreateNativeWidgetSiblings attribute, configuring high DPI support for different Qt versions, and initializing the QWK::WidgetWindowAgent. This setup ensures proper QWindowKit functionality and compatibility. ```cpp #include int main(int argc, char *argv[]) { // CRITICAL: Must be set before QApplication is created // Prevents Qt from creating native widget siblings which breaks QWindowKit QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); // Optional: High DPI support #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) QGuiApplication::setHighDpiScaleFactorRoundingPolicy( Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif QApplication app(argc, argv); // Create window and setup agent early auto mainWindow = new QMainWindow(); mainWindow->setAttribute(Qt::WA_DontCreateNativeAncestors); auto agent = new QWK::WidgetWindowAgent(mainWindow); agent->setup(mainWindow); // Must be called before setting size constraints // NOW safe to set size constraints mainWindow->setMinimumSize(640, 480); mainWindow->resize(800, 600); mainWindow->show(); return app.exec(); } ``` -------------------------------- ### Setup WidgetWindowAgent in Qt Widgets Source: https://github.com/stdware/qwindowkit/blob/main/README.md This C++ code snippet shows how to set up the `WidgetWindowAgent` for a top-level `QWidget` in a Qt Widgets application using QWindowKit. It demonstrates creating an instance of `WidgetWindowAgent` and calling its `setup()` method, ensuring it's done as early as possible, preferably in the constructor or immediately after widget creation, to correctly handle window size constraints. ```cpp #include MyWidget::MyWidget(QWidget *parent) { // ... auto agent = new QWK::WidgetWindowAgent(this); agent->setup(this); // ... } // Alternative initialization after construction: auto w = new MyWidget(); auto agent = new QWK::WidgetWindowAgent(w); agent->setup(w); ``` -------------------------------- ### Define QWindowKit Example Target with CMake Source: https://github.com/stdware/qwindowkit/blob/main/examples/CMakeLists.txt This macro defines a CMake target for a QWindowKit example application. It enables automatic meta-object, UI, and resource compilation, adds the executable, and configures platform-specific resources like icons and manifests for Windows and macOS. ```cmake set(QWK_EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR}) macro(qwk_add_example _target) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) add_executable(${_target}) qm_configure_target(${_target} ${ARGN}) qm_add_win_rc(${_target} ICON ${QWK_EXAMPLES_DIR}/shared/resources/app/example.ico) qm_add_win_manifest(${_target}) qm_add_mac_bundle(${_target} ICON ${QWK_EXAMPLES_DIR}/shared/resources/app/example.icns) endmacro() ``` -------------------------------- ### CMake Project and Library Setup for QWKQuick Source: https://github.com/stdware/qwindowkit/blob/main/src/quick/CMakeLists.txt Configures a CMake project for the QWKQuick library. It defines the project version, language, and dynamically adds source files based on the operating system. It also specifies build features, library dependencies, and Qt module linking. This setup is crucial for building the QWKQuick module. ```cmake project(QWKQuick VERSION ${QWINDOWKIT_VERSION} LANGUAGES CXX ) set(_src qwkquickglobal.h qwkquickglobal.cpp quickitemdelegate_p.h quickitemdelegate.cpp quickwindowagent.h quickwindowagent_p.h quickwindowagent.cpp ) if(WIN32) list(APPEND _src quickwindowagent_win.cpp) elseif(APPLE) list(APPEND _src quickwindowagent_mac.cpp) endif() qwk_add_library(${PROJECT_NAME} AUTOGEN SOURCES ${_src} FEATURES cxx_std_17 LINKS QWKCore QT_LINKS Core Gui Quick QT_INCLUDE_PRIVATE Core Gui Quick INCLUDE_PRIVATE * PREFIX QWK_QUICK ) set(QWINDOWKIT_ENABLED_TARGETS ${QWINDOWKIT_ENABLED_TARGETS} ${PROJECT_NAME} PARENT_SCOPE) set(QWINDOWKIT_ENABLED_SUBDIRECTORIES ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} quick PARENT_SCOPE) ``` -------------------------------- ### Integrate QWindowKit into CMake Project Source: https://github.com/stdware/qwindowkit/blob/main/README.md This code snippet shows how to find and link QWindowKit components within a CMake project after it has been installed. It first configures the build to locate the QWindowKit installation directory and then uses find_package to import the Core, Widgets, and Quick modules. Finally, it demonstrates linking these modules to target applications. ```cmake cmake -B build -DQWindowKit_DIR=/path/install/lib/cmake/QWindowKit find_package(QWindowKit COMPONENTS Core Widgets Quick REQUIRED) target_link_libraries(widgets_app PUBLIC QWindowKit::Widgets) target_link_libraries(quick_app PUBLIC QWindowKit::Quick) ``` -------------------------------- ### QWindowKit CMake Configuration Setup Source: https://github.com/stdware/qwindowkit/blob/main/src/CMakeLists.txt Initializes QWindowKit build settings, including generated include directories, enabled targets, and subdirectories. It also sets up configuration definitions for various features like Qt window context, style agent, and Windows system borders. ```cmake qm_import(Preprocess) set(QWINDOWKIT_GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../include) set(QWINDOWKIT_BUILD_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../etc/include) set(QWINDOWKIT_ENABLED_TARGETS) set(QWINDOWKIT_ENABLED_SUBDIRECTORIES) # ---------------------------------- # Configurations # ---------------------------------- set(QMSETUP_DEFINITION_SCOPE DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(QMSETUP_DEFINITION_NUMERICAL on) qm_add_definition(QWINDOWKIT_ENABLE_QT_WINDOW_CONTEXT CONDITION QWINDOWKIT_ENABLE_QT_WINDOW_CONTEXT ) qm_add_definition(QWINDOWKIT_ENABLE_STYLE_AGENT CONDITION QWINDOWKIT_ENABLE_STYLE_AGENT ) qm_add_definition(QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS CONDITION QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS ) qm_generate_config(${QWINDOWKIT_BUILD_INCLUDE_DIR}/QWKCore/qwkconfig.h) if(QWINDOWKIT_INSTALL) install(FILES ${QWINDOWKIT_BUILD_INCLUDE_DIR}/QWKCore/qwkconfig.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${QWINDOWKIT_INSTALL_NAME}/QWKCore ) endif() ``` -------------------------------- ### Integrate QWindowKit into QMake Project Source: https://github.com/stdware/qwindowkit/blob/main/README.md This code snippet illustrates how to include QWindowKit into QMake projects. It shows the necessary 'include' directives for both Widgets and Quick applications, pointing to the respective `.pri` files generated during the QWindowKit installation. This allows QMake projects to utilize QWindowKit functionalities. ```make # WidgetsApp.pro include("/path/install/share/QWindowKit/qmake/QWKWidgets.pri") # QuickApp.pro include("/path/install/share/QWindowKit/qmake/QWKQuick.pri") ``` -------------------------------- ### Integrate QWindowKit Widgets with QMake Source: https://context7.com/stdware/qwindowkit/llms.txt This QMake project file (.pro) demonstrates how to include the QWindowKit Widgets module in a Qt project. It specifies C++17 standard, includes the necessary QWKWidgets.pri file from the QWindowKit installation path, and lists the source and header files for the application. ```qmake # MyWidgetsApp.pro QT += core gui widgets CONFIG += c++17 # Include QWindowKit Widgets module include(/path/to/install/share/QWindowKit/qmake/QWKWidgets.pri) SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h ``` -------------------------------- ### Qt Widgets Window Agent Setup and Configuration (C++) Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code demonstrates how to set up and configure the WidgetWindowAgent in a Qt Widgets application. It covers creating and integrating a custom title bar, registering system buttons for enhanced window control (including Windows 11 Snap Layout support), and defining interactive areas that should not trigger window dragging. Dependencies include Qt Widgets and QWKWidgets. ```cpp #include #include #include class MyMainWindow : public QMainWindow { public: MyMainWindow(QWidget *parent = nullptr) : QMainWindow(parent) { // Step 1: Create and setup window agent early auto windowAgent = new QWK::WidgetWindowAgent(this); windowAgent->setup(this); // Must be called before setting size constraints // Step 2: Create title bar components auto menuBar = new QMenuBar(this); menuBar->addMenu(new QMenu(tr("File"), menuBar)); auto titleLabel = new QLabel(tr("My Application")); titleLabel->setAlignment(Qt::AlignCenter); auto iconButton = new QWK::WindowButton(); auto minButton = new QWK::WindowButton(); auto maxButton = new QWK::WindowButton(); maxButton->setCheckable(true); auto closeButton = new QWK::WindowButton(); // Step 3: Create WindowBar container auto windowBar = new QWK::WindowBar(); windowBar->setIconButton(iconButton); windowBar->setMinButton(minButton); windowBar->setMaxButton(maxButton); windowBar->setCloseButton(closeButton); windowBar->setMenuBar(menuBar); windowBar->setTitleLabel(titleLabel); windowBar->setHostWidget(this); // Step 4: Register title bar with agent windowAgent->setTitleBar(windowBar); // Step 5: Register system buttons (enables Windows 11 Snap Layout) windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton); windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); // Step 6: Mark interactive widgets (they won't be draggable) windowAgent->setHitTestVisible(menuBar, true); // Step 7: Connect button signals to window actions connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized); connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this](bool max) { max ? showMaximized() : showNormal(); }); connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close); setMenuWidget(windowBar); // macOS: Set system button area callback #ifdef Q_OS_MAC windowAgent->setSystemButtonAreaCallback([](const QSize &size) { static constexpr const int width = 75; return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); }); #endif // Now safe to set size constraints resize(800, 600); setMinimumSize(400, 300); } }; ``` -------------------------------- ### Configure Doxygen Documentation Generation (CMake) Source: https://github.com/stdware/qwindowkit/blob/main/src/CMakeLists.txt This snippet configures the Doxygen documentation generation process. It finds the Doxygen executable if not already found, sets up installation options, and defines the input files and targets for Doxygen. It also specifies compilation definitions and generates a tag file for cross-referencing. ```cmake if(QWINDOWKIT_BUILD_DOCUMENTATIONS) if(NOT DOXYGEN_EXECUTABLE) find_package(Doxygen REQUIRED) endif() set(_install_options) if(QWINDOWKIT_INSTALL) set(_install_options INSTALL_DIR share/doc/${QWINDOWKIT_INSTALL_NAME}) endif() set(_doc_targets ${QWINDOWKIT_ENABLED_TARGETS}) set(QWINDOWKIT_DOXYGEN_TAGFILE ${CMAKE_BUILD_SHARE_DIR}/doc/${QWINDOWKIT_INSTALL_NAME}/${QWINDOWKIT_INSTALL_NAME}_tagfile.xml CACHE FILEPATH "QWindowKit doxygen tag file path" FORCE ) qm_import(Doxygen) qm_setup_doxygen(QWindowKit_RunDoxygen NAME "QWindowKit" DESCRIPTION "${QWINDOWKIT_DESCRIPTION}" MDFILE ../README.md OUTPUT_DIR ${CMAKE_BUILD_SHARE_DIR}/doc/${QWINDOWKIT_INSTALL_NAME} INPUT ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} TARGETS ${_doc_targets} DEPENDS ${_doc_targets} NO_EXPAND_MACROS Q_OBJECT Q_GADGET Q_DECLARE_TR_FUNCTIONS COMPILE_DEFINITIONS Q_SIGNALS=Q_SIGNALS Q_SLOTS=Q_SLOTS GENERATE_TAGFILE "${QWINDOWKIT_DOXYGEN_TAGFILE}" ${_install_options} ) endif() ``` -------------------------------- ### Setup Windows 10/11 Effects with QWKWidgets Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code configures advanced Windows 10/11 features like Snap Layout, DWM blur, dark mode, and Mica/Acrylic materials using QWK::WidgetWindowAgent. It allows enabling or disabling these effects and interacting with system borders and title bar heights. ```cpp #include void setupWindowsEffects(QWK::WidgetWindowAgent *agent) { // Enable Windows 11 Snap Layout (requires system button registration) agent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); agent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); agent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); // Windows 10+ DWM blur effect agent->setWindowAttribute("dwm-blur", true); // Windows 10+ dark mode agent->setWindowAttribute("dark-mode", true); // Windows 11 Mica material (mutually exclusive) agent->setWindowAttribute("mica", true); // Windows 11 Mica-Alt material (alternative Mica style) agent->setWindowAttribute("mica-alt", true); // Windows 11 Acrylic material agent->setWindowAttribute("acrylic-material", true); // Disable effects (set to false or restart with different attribute) agent->setWindowAttribute("mica", false); // Show system context menu at specific position agent->showSystemMenu(QPoint(100, 100)); // Read system border thickness int borderThickness = agent->windowAttribute("border-thickness").toInt(); int titleBarHeight = agent->windowAttribute("title-bar-height").toInt(); qDebug() << "Border:" << borderThickness << "TitleBar:" << titleBarHeight; } ``` -------------------------------- ### CMake Macro for QWindowKit Libraries Source: https://github.com/stdware/qwindowkit/blob/main/src/CMakeLists.txt Defines a CMake macro `qwk_add_library` to simplify adding libraries to the QWindowKit project. It handles options like automatic moc/uic/rcc generation, static/shared library types, Windows resource compilation, prefixing, and installation rules. ```cmake macro(qwk_add_library _target) set(options AUTOGEN NO_SYNC_INCLUDE NO_WIN_RC) set(oneValueArgs SYNC_INCLUDE_PREFIX PREFIX) set(multiValueArgs SYNC_INCLUDE_OPTIONS) cmake_parse_arguments(FUNC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(FUNC_AUTOGEN) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) endif() if(QWINDOWKIT_BUILD_STATIC) set(_type STATIC) else() set(_type SHARED) endif() add_library(${_target} ${_type}) if(WIN32 AND NOT FUNC_NO_WIN_RC AND(${_type} STREQUAL "SHARED")) qm_add_win_rc(${_target} NAME ${QWINDOWKIT_INSTALL_NAME} DESCRIPTION ${QWINDOWKIT_DESCRIPTION} COPYRIGHT ${QACTIONKIT_COPYRIGHT} ) endif() if(FUNC_PREFIX) set(_prefix_option PREFIX ${FUNC_PREFIX}) else() set(_prefix_option) endif() # Set global definitions qm_export_defines(${_target} ${_prefix_option}) # Configure target qm_configure_target(${_target} ${FUNC_UNPARSED_ARGUMENTS}) # Add include directories target_include_directories(${_target} PRIVATE ${QWINDOWKIT_BUILD_INCLUDE_DIR}) target_include_directories(${_target} PRIVATE .) # Library name if(${_target} MATCHES "^QWK(.+)") set(_name ${CMAKE_MATCH_1}) set_target_properties(${_target} PROPERTIES EXPORT_NAME ${_name}) else() set(_name ${_target}) endif() add_library(${QWINDOWKIT_INSTALL_NAME}::${_name} ALIAS ${_target}) if(FUNC_SYNC_INCLUDE_PREFIX) set(_inc_name ${FUNC_SYNC_INCLUDE_PREFIX}) else() set(_inc_name ${_target}) endif() set(_install_options) if(QWINDOWKIT_INSTALL) install(TARGETS ${_target} EXPORT ${QWINDOWKIT_INSTALL_NAME}Targets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL ) target_include_directories(${_target} PUBLIC "$" ) set(_install_options INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${QWINDOWKIT_INSTALL_NAME}/${_inc_name}" ) endif() if(NOT FUNC_NO_SYNC_INCLUDE) # Generate a standard include directory in build directory qm_sync_include(. "${QWINDOWKIT_GENERATED_INCLUDE_DIR}/${_inc_name}" ${_install_options} ${FUNC_SYNC_INCLUDE_OPTIONS} FORCE ) target_include_directories(${_target} PUBLIC "$" ) endif() endmacro() ``` -------------------------------- ### Manage Window Attributes with WindowAgentBase Source: https://context7.com/stdware/qwindowkit/llms.txt Demonstrates how to use the WindowAgentBase class to set and get various window attributes for visual effects and platform-specific features. This includes enabling Mica, dark mode, DWM blur, Acrylic materials on Windows, and blur effects on macOS. It also shows how to hide native system buttons and read window properties. ```cpp #include // Enable Windows 11 Mica material effect auto agent = new QWK::WidgetWindowAgent(this); agent->setup(this); agent->setWindowAttribute("mica", true); // Enable dark mode (Windows 10+) agent->setWindowAttribute("dark-mode", true); // Enable DWM blur (Windows 10+) agent->setWindowAttribute("dwm-blur", true); // Enable Acrylic material (Windows 11) agent->setWindowAttribute("acrylic-material", true); // macOS blur effects agent->setWindowAttribute("blur-effect", "dark"); // "dark", "light", or "none" // Hide native system buttons on macOS (use custom buttons instead) agent->setWindowAttribute("no-system-buttons", true); // Read-only attributes QVariant borderThickness = agent->windowAttribute("border-thickness"); // Windows QVariant titleBarHeight = agent->windowAttribute("title-bar-height"); // All platforms // Show system context menu at cursor position (Windows only) agent->showSystemMenu(QCursor::pos()); // Center window on current screen agent->centralize(); // Bring window to top agent->raise(); ``` -------------------------------- ### Initialize Qt Application with QWindowKit Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code sets up a Qt application, enables alpha channel for potential transparency effects, registers QWindowKit types for QML integration, and loads the main QML file. It's the entry point for a QWindowKit-enabled application. ```cpp // main.cpp #include #include #include int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); // Enable alpha channel for Windows special effects QQuickWindow::setDefaultAlphaBuffer(true); QQmlApplicationEngine engine; // Register QWindowKit types for QML QWK::registerTypes(&engine); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); return app.exec(); } ``` -------------------------------- ### Integrate QWindowKit Quick with QMake Source: https://context7.com/stdware/qwindowkit/llms.txt This QMake project file (.pro) shows how to incorporate the QWindowKit Quick module into a Qt Quick project. It includes essential Qt modules (core, gui, quick, qml), sets the C++ standard to C++17, includes the QWKQuick.pri file, and lists the source files and QML resources. ```qmake # MyQuickApp.pro QT += core gui quick qml CONFIG += c++17 # Include QWindowKit Quick module include(/path/to/install/share/QWindowKit/qmake/QWKQuick.pri) SOURCES += main.cpp RESOURCES += qml.qrc ``` -------------------------------- ### Setting Up Title Bar with WidgetWindowAgent Source: https://github.com/stdware/qwindowkit/blob/main/README.md This snippet demonstrates how to associate a custom title bar widget with the WindowAgent, configure system buttons for snap layouts, and enable hit-test visibility for the title bar. It requires the `WidgetFrame` library and `WidgetWindowAgent`. The output is the configured WindowAgent. ```c++ agent->setTitleBar(myTitleBar); agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, myTitleBar->iconButton()); agent->setSystemButton(QWK::WindowAgentBase::Minimize, myTitleBar->minButton()); agent->setSystemButton(QWK::WindowAgentBase::Maximize, myTitleBar->maxButton()); agent->setSystemButton(QWK::WindowAgentBase::Close, myTitleBar->closeButton()); agent->setHitTestVisible(myTitleBar->menuBar(), true); ``` -------------------------------- ### QWindowKit Main Project Structure Source: https://github.com/stdware/qwindowkit/blob/main/src/CMakeLists.txt Includes the core QWindowKit module and conditionally includes the widgets and quick modules based on build flags. This sets up the overall project structure and dependencies. ```cmake # ---------------------------------- # Main Project # ---------------------------------- add_subdirectory(core) if(QWINDOWKIT_BUILD_WIDGETS) add_subdirectory(widgets) endif() if(QWINDOWKIT_BUILD_QUICK) add_subdirectory(quick) endif() # ---------------------------------- # Documentation ``` -------------------------------- ### Detect System Theme Changes with QWK::StyleAgent (C++) Source: https://context7.com/stdware/qwindowkit/llms.txt This snippet demonstrates how to use QWK::StyleAgent to detect and react to system theme changes (Light, Dark, HighContrast) in a Qt application. It initializes the agent, checks the current theme, and connects to the systemThemeChanged signal to update the theme dynamically. Ensure the QWKCore module is linked. ```cpp #include class MyApplication : public QObject { public: MyApplication() { auto styleAgent = new QWK::StyleAgent(this); // Get current system theme QWK::StyleAgent::SystemTheme theme = styleAgent->systemTheme(); switch (theme) { case QWK::StyleAgent::Light: applyLightTheme(); break; case QWK::StyleAgent::Dark: applyDarkTheme(); break; case QWK::StyleAgent::HighContrast: applyHighContrastTheme(); break; case QWK::StyleAgent::Unknown: default: applyDefaultTheme(); break; } // Listen for theme changes connect(styleAgent, &QWK::StyleAgent::systemThemeChanged, this, [styleAgent, this]() { QWK::StyleAgent::SystemTheme newTheme = styleAgent->systemTheme(); qDebug() << "System theme changed to:" << newTheme; updateTheme(newTheme); }); } private: void applyLightTheme() { /* ... */ } void applyDarkTheme() { /* ... */ } void applyHighContrastTheme() { /* ... */ } void applyDefaultTheme() { /* ... */ } void updateTheme(QWK::StyleAgent::SystemTheme theme) { /* ... */ } }; ``` -------------------------------- ### Registering QWindowKit with QML Source: https://github.com/stdware/qwindowkit/blob/main/README.md This code snippet shows how to register the QWindowKit module with a QQmlApplicationEngine, making its types and classes available for use in Qt Quick applications. It requires including `qwkquickglobal.h` and calling `QWK::registerTypes(&engine)`. The output is a QML-enabled engine. ```c++ #include int main(int argc, char *argv[]) { // ... QQmlApplicationEngine engine; // ... QWK::registerTypes(&engine); // ... } ``` -------------------------------- ### Qt Widgets Application Initialization Source: https://github.com/stdware/qwindowkit/blob/main/README.md This C++ code snippet demonstrates the essential initialization steps for a Qt Widgets application using QWindowKit. It includes setting the `Qt::AA_DontCreateNativeWidgetSiblings` attribute on the `QApplication` object, which is crucial for QWindowKit's internal workings before any widgets are constructed. ```cpp #include int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings) // ... } ``` -------------------------------- ### Setting Window Attributes in QWindowKit Source: https://github.com/stdware/qwindowkit/blob/main/README.md This snippet illustrates how to apply experimental window attributes, such as system effects like 'mica' or 'acrylic', on Windows 11. It requires the `WidgetWindowAgent` and accepts a key-value pair for the attribute. The output is a window with the specified attribute applied. ```c++ agent->setWindowAttribute("mica", true); ``` -------------------------------- ### QML Window Management with WindowAgent Source: https://context7.com/stdware/qwindowkit/llms.txt This QML code defines a frameless window and utilizes the WindowAgent to manage its title bar, system buttons (icon, minimize, maximize, close), and window attributes like dark mode. It demonstrates how to integrate window management features into a Qt Quick application. ```qml // FramelessWindow.qml import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import QWindowKit 1.0 Window { id: window width: 800 height: 600 visible: false // Hide until setup complete color: "#1E1E1E" title: qsTr("My Application") Component.onCompleted: { windowAgent.setup(window) windowAgent.setWindowAttribute("dark-mode", true) window.visible = true } WindowAgent { id: windowAgent } // Title bar Rectangle { id: titleBar anchors { top: parent.top left: parent.left right: parent.right } height: 32 color: "transparent" Component.onCompleted: windowAgent.setTitleBar(titleBar) Image { id: iconButton anchors { verticalCenter: parent.verticalCenter left: parent.left leftMargin: 10 } width: 18 height: 18 source: "qrc:///icon.png" Component.onCompleted: windowAgent.setSystemButton(WindowAgent.WindowIcon, iconButton) } Text { anchors { verticalCenter: parent.verticalCenter left: iconButton.right leftMargin: 10 } text: window.title font.pixelSize: 14 color: "#ECECEC" } Row { anchors { top: parent.top right: parent.right } height: parent.height Button { id: minButton height: parent.height text: "−" onClicked: window.showMinimized() Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Minimize, minButton) } Button { id: maxButton height: parent.height text: window.visibility === Window.Maximized ? "🗗" : "🗖" onClicked: { if (window.visibility === Window.Maximized) { window.showNormal() } else { window.showMaximized() } } Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Maximize, maxButton) } Button { id: closeButton height: parent.height text: "✕" onClicked: window.close() Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Close, closeButton) } } } // Application content Label { anchors.centerIn: parent text: "Hello QWindowKit!" font.pointSize: 24 } } ``` -------------------------------- ### QML Dynamic Theme and Effect Switching Source: https://context7.com/stdware/qwindowkit/llms.txt This QML code configures a window with a context menu for theme switching (light/dark) and applying platform-specific visual effects like DWM Blur, Mica, and Acrylic Material. It relies on QWindowKit for window attribute manipulation and Qt Quick Controls for UI elements. The menu items dynamically update window properties and attributes based on user selection. Platform-specific effects are conditionally enabled for Windows. ```qml import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import Qt.labs.platform 1.1 import QWindowKit 1.0 Window { id: window width: 800 height: 600 color: isDarkMode ? "#1E1E1E" : "#FFFFFF" property bool isDarkMode: true Component.onCompleted: { windowAgent.setup(window) windowAgent.setWindowAttribute("dark-mode", isDarkMode) window.visible = true } WindowAgent { id: windowAgent } TapHandler { acceptedButtons: Qt.RightButton onTapped: contextMenu.open() } Menu { id: contextMenu Menu { title: qsTr("Theme") MenuItem { text: qsTr("Light") checkable: true checked: !window.isDarkMode onTriggered: { window.isDarkMode = false windowAgent.setWindowAttribute("dark-mode", false) } } MenuItem { text: qsTr("Dark") checkable: true checked: window.isDarkMode onTriggered: { window.isDarkMode = true windowAgent.setWindowAttribute("dark-mode", true) } } } Menu { title: qsTr("Special Effects") enabled: Qt.platform.os === "windows" MenuItem { text: qsTr("None") checkable: true checked: true onTriggered: { window.color = window.isDarkMode ? "#1E1E1E" : "#FFFFFF" windowAgent.setWindowAttribute("dwm-blur", false) windowAgent.setWindowAttribute("acrylic-material", false) windowAgent.setWindowAttribute("mica", false) windowAgent.setWindowAttribute("mica-alt", false) } } MenuItem { text: qsTr("DWM Blur") checkable: true onTriggered: { window.color = "transparent" windowAgent.setWindowAttribute("acrylic-material", false) windowAgent.setWindowAttribute("mica", false) windowAgent.setWindowAttribute("mica-alt", false) windowAgent.setWindowAttribute("dwm-blur", true) } } MenuItem { text: qsTr("Mica") checkable: true onTriggered: { window.color = "transparent" windowAgent.setWindowAttribute("dwm-blur", false) windowAgent.setWindowAttribute("acrylic-material", false) windowAgent.setWindowAttribute("mica-alt", false) windowAgent.setWindowAttribute("mica", true) } } MenuItem { text: qsTr("Acrylic Material") checkable: true onTriggered: { window.color = "transparent" windowAgent.setWindowAttribute("dwm-blur", false) windowAgent.setWindowAttribute("mica", false) windowAgent.setWindowAttribute("mica-alt", false) windowAgent.setWindowAttribute("acrylic-material", true) } } } } } ``` -------------------------------- ### Integrate macOS Features with QWKWidgets Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code snippet demonstrates how to integrate native macOS features using QWK::WidgetWindowAgent. It covers hiding/showing system buttons, applying blur effects, and defining the system button area either through a widget or a callback function. It also retrieves the title bar height. ```cpp #include void setupMacOSFeatures(QWK::WidgetWindowAgent *agent, QWidget *mainWindow) { #ifdef Q_OS_MAC // Option 1: Hide native system buttons (use custom buttons) agent->setWindowAttribute("no-system-buttons", true); // Option 2: Keep native system buttons (default behavior) agent->setWindowAttribute("no-system-buttons", false); // Set blur effect agent->setWindowAttribute("blur-effect", "dark"); // Dark blur agent->setWindowAttribute("blur-effect", "light"); // Light blur agent->setWindowAttribute("blur-effect", "none"); // No blur // Option A: Set system button area widget container QWidget *buttonArea = new QWidget(mainWindow); buttonArea->setFixedWidth(75); agent->setSystemButtonArea(buttonArea); // Option B: Set system button area using callback (more flexible) agent->setSystemButtonAreaCallback([](const QSize &windowSize) -> QRect { // Return rectangle for system buttons (traffic lights) // Typically in top-left or top-right corner constexpr int buttonWidth = 75; constexpr int buttonHeight = 32; // Top-right positioning return QRect( QPoint(windowSize.width() - buttonWidth, 0), QSize(buttonWidth, buttonHeight) ); }); // Get system button area widget QWidget *area = agent->systemButtonArea(); // Read title bar height int titleBarHeight = agent->windowAttribute("title-bar-height").toInt(); qDebug() << "macOS title bar height:" << titleBarHeight; #endif } ``` -------------------------------- ### Control Hit-Testing for Interactive Widgets with QWKWidgets Source: https://context7.com/stdware/qwindowkit/llms.txt This C++ code demonstrates how to manage hit-testing for widgets within a title bar using QWK::WidgetWindowAgent. It shows how to register a title bar, designate specific widgets as interactive (receiving mouse events and not being draggable), and check their hit-test visibility. System buttons are inherently hit-test visible. ```cpp #include void setupHitTesting(QWK::WidgetWindowAgent *agent) { // Create title bar with interactive elements auto titleBar = new QWidget(); auto menuBar = new QMenuBar(titleBar); auto searchBox = new QLineEdit(titleBar); auto settingsButton = new QPushButton("Settings", titleBar); // Register title bar (by default, all areas are draggable) agent->setTitleBar(titleBar); // Mark widgets as hit-test visible (they will receive mouse events) // These areas will NOT be draggable agent->setHitTestVisible(menuBar, true); agent->setHitTestVisible(searchBox, true); agent->setHitTestVisible(settingsButton, true); // Check if widget is hit-test visible bool isVisible = agent->isHitTestVisible(menuBar); qDebug() << "MenuBar receives mouse events:" << isVisible; // Make widget non-interactive again (becomes draggable) agent->setHitTestVisible(searchBox, false); // System buttons are automatically hit-test visible agent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); // closeButton automatically receives mouse events } ``` -------------------------------- ### Conditional Subdirectory Inclusion in CMake Source: https://github.com/stdware/qwindowkit/blob/main/examples/CMakeLists.txt This CMake code demonstrates conditional inclusion of subdirectories based on build variables. It adds the 'shared' subdirectory unconditionally, and then adds 'mainwindow' and 'qml' subdirectories only if specific build flags (`QWINDOWKIT_BUILD_WIDGETS` and `QWINDOWKIT_BUILD_QUICK`) are enabled, respectively. ```cmake add_subdirectory(shared) if(QWINDOWKIT_BUILD_WIDGETS) add_subdirectory(mainwindow) endif() if(QWINDOWKIT_BUILD_QUICK) add_subdirectory(qml) endif() ``` -------------------------------- ### QWKWidgets Library Definition (CMake) Source: https://github.com/stdware/qwindowkit/blob/main/src/widgets/CMakeLists.txt Defines the QWKWidgets library using CMake. It sets the project name and version, specifies C++17 as a feature, links against QWKCore, and includes necessary Qt modules (Core, Gui, Widgets). It also handles platform-specific source files for Windows and macOS. ```cmake project(QWKWidgets VERSION ${QWINDOWKIT_VERSION} LANGUAGES CXX ) set(_src qwkwidgetsglobal.h widgetitemdelegate_p.h widgetitemdelegate.cpp widgetwindowagent.h widgetwindowagent_p.h widgetwindowagent.cpp ) if(WIN32) list(APPEND _src widgetwindowagent_win.cpp) elseif(APPLE) list(APPEND _src widgetwindowagent_mac.cpp) endif() qwk_add_library(${PROJECT_NAME} AUTOGEN SOURCES ${_src} FEATURES cxx_std_17 LINKS QWKCore QT_LINKS Core Gui Widgets QT_INCLUDE_PRIVATE Core Gui Widgets INCLUDE_PRIVATE * PREFIX QWK_WIDGETS ) set(QWINDOWKIT_ENABLED_TARGETS ${QWINDOWKIT_ENABLED_TARGETS} ${PROJECT_NAME} PARENT_SCOPE) set(QWINDOWKIT_ENABLED_SUBDIRECTORIES ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} widgets PARENT_SCOPE) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.