{ "name": "LazyLoader", "module": "Quickshell", "type": "class", "super": { "type": "local", "module": "Quickshell", "name": "Reloadable" }, "description": "Asynchronous component loader.", "details": "The LazyLoader can be used to prepare components that don't need to be\ncreated immediately, such as windows that aren't visible until triggered\nby another action. It works on creating the component in the gaps between\nframe rendering to prevent blocking the interface thread.\nIt can also be used to preserve memory by loading components only\nwhen you need them and unloading them afterward.\n\nNote that when reloading the UI due to changes, lazy loaders will always\nload synchronously so windows can be reused.\n\n#### Example\nThe following example creates a PopupWindow asynchronously as the bar loads.\nThis means the bar can be shown onscreen before the popup is ready, however\ntrying to show the popup before it has finished loading in the background\nwill cause the UI thread to block.\n\n```qml\nimport QtQuick\nimport QtQuick.Controls\nimport Quickshell\n\nQS_Quickshell_ShellRoot {\n QS_Quickshell_PanelWindow {\n id: window\n height: 50\n\n anchors {\n bottom: true\n left: true\n right: true\n }\n\n QS_Quickshell_LazyLoader {\n id: popupLoader\n\n // start loading immediately\n loading: true\n\n // this window will be loaded in the background during spare\n // frame time unless active is set to true, where it will be\n // loaded in the foreground\n QS_Quickshell_PopupWindow {\n // position the popup above the button\n parentWindow: window\n relativeX: window.width / 2 - width / 2\n relativeY: -height\n\n // some heavy component here\n\n width: 200\n height: 200\n }\n }\n\n QT_qtquick11controls_Button {\n anchors.centerIn: parent\n text: \"show popup\"\n\n // accessing popupLoader.item will force the loader to\n // finish loading on the UI thread if it isn't finished yet.\n onClicked: popupLoader.item.visible = !popupLoader.item.visible\n }\n }\n}\n```\n\n> [!WARNING]\n> Components that internally load other components must explicitly\n> support asynchronous loading to avoid blocking.\n> \n> Notably, {{< qmltypelink type=\"local\" module=\"Quickshell\" name=\"Variants\" mtype=\"\" mname=\"\" >}} does not currently support asynchronous\n> loading, meaning using it inside a LazyLoader will block similarly to not\n> having a loader to start with.\n\n> [!WARNING]\n> LazyLoaders do not start loading before the first window is created,\n> meaning if you create all windows inside of lazy loaders, none of them will ever load.\n\n", "properties": { "loading": { "type": { "type": "qt", "module": "qml", "name": "bool" }, "details": "If the loader is actively loading.\n\nIf the component is not loaded, setting this property to true will start\nloading it asynchronously. If the component is already loaded, setting\nthis property has no effect.\n\nSee also: {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"activeAsync\" >}}.\n" }, "activeAsync": { "type": { "type": "qt", "module": "qml", "name": "bool" }, "details": "If the component is fully loaded.\n\nSetting this property to true will asynchronously load the component similarly to\n{{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"loading\" >}}. Reading it or setting it to false will behanve\nthe same as {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"active\" >}}.\n" }, "source": { "type": { "type": "qt", "module": "qml", "name": "string" }, "details": "The URI to load the component from. Mutually exclusive to {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"component\" >}}.\n" }, "active": { "type": { "type": "qt", "module": "qml", "name": "bool" }, "details": "If the component is fully loaded.\n\nSetting this property to `true` will force the component to load to completion,\nblocking the UI, and setting it to `false` will destroy the component, requiring\nit to be loaded again.\n\nSee also: {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"activeAsync\" >}}.\n" }, "component": { "type": { "type": "qt", "module": "qml.QtQml", "name": "Component" }, "details": "The component to load. Mutually exclusive to {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"source\" >}}.\n", "flags": [ "default" ] }, "item": { "type": { "type": "qt", "module": "qml.QtQml", "name": "QtObject" }, "details": "The fully loaded item if the loader is {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"loading\" >}} or {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"active\" >}}, or `null`\nif neither {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"loading\" >}} nor {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"active\" >}}.\n\nNote that the item is owned by the LazyLoader, and destroying the LazyLoader\nwill destroy the item.\n\n> [!WARNING]\n> If you access the `item` of a loader that is currently loading,\n> it will block as if you had set `active` to true immediately beforehand.\n> \n> You can instead set {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"prop\" mname=\"loading\" >}} and listen to {{< qmltypelink type=\"\" module=\"\" name=\"\" mtype=\"signal\" mname=\"activeChanged\" >}} signal to\n> ensure loading happens asynchronously.\n\n", "flags": [ "readonly" ] } }, "functions": [], "signals": {}, "variants": {} }