Hojas superpuestas

Las hojas superpuestas pueden servir para diversos usos, tanto para servir datos como para introducirlos.

A Kirigami.OverlaySheet is a simple component that you can use to supplement the content being displayed on an application's page. They are designed to display long, vertical content and can accommodate content longer than the application window itself.

Se pueden descartar haciendo clic o tocando fuera de su área, o pulsando el icono 'x' que hay en la cabecera de la hoja.

Más información sobre la hoja

Para poder usar una hoja superpuesta, debemos crearla dentro de la página de Kirigami en la que queremos que aparezca.

import QtQuick 2.15
import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami

Kirigami.Page {
    id: page
    Layout.fillWidth: true

    Kirigami.OverlaySheet {
        id: mySheet
        Controls.Label {
            Layout.fillWidth: true
            wrapMode: Text.WordWrap
            text: "Weeeeee, overlay sheet!"
        }
    }
}
Hoja superpuesta sencilla que solo contiene texto

Overlay sheets come with methods we can use to open() or close() them as we see fit. By default overlay sheets are hidden, so at the very least we will need to use the open() method.

Controls.Button {
    text: "Open mySheet"
    onClicked: mySheet.open()
}

When opened, this overlay sheet will appear centered vertically and horizontally within its parent page. Horizontally it will be bounded by its parent even if the width of its contents exceeds its parent's. If the sheet's vertical length exceeds its parent's, then the sheet will be displayed starting from its top position, and will be scrollable.

Hoja global

If you want to display the sheet as a global sheet—one that spans across the entire width of the application, regardless of the page it is a child to—we have to reparent our overlay sheet to our application window's overlay property. We can do this with the parent property.

Kirigami.OverlaySheet {
    id: mySheet

    parent: applicationWindow().overlay

    Controls.Label {
        Layout.fillWidth: true
        wrapMode: Text.WordWrap
        text: "Weeeeee, overlay sheet!"
    }
}
Hoja superpuesta no global

Hoja superpuesta no global

Hoja superpuesta global

Hoja superpuesta global

Tamaño fijo

A sheet is greedy and will take the maximum amount of available width in a page if needed. We can avoid this by specifying an implicitWidth or a Layout.preferredWidth for its child elements, which will limit how much the sheet will grow width wise.

Kirigami.OverlaySheet {
    id: mySheet
    Controls.Label {
        Layout.preferredWidth: Kirigami.Units.gridUnit * 25
        wrapMode: Text.WordWrap
        text: "Weeeeee, overlay sheet! I'm so excited!! WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!!!"
    }
}
Hoja superpuesta de anchura no fija

Hoja superpuesta de anchura no fija

Hoja superpuesta de anchura fija

Hoja superpuesta de anchura fija

Encabezados y pies de página

Overlay sheets come by default with a header that only contains a button for closing our overlay sheet. We can add a Kirigami.Heading as a title in our header to make it easy for users to understand what the sheet is for. This is done by setting header to contain our heading component.

Kirigami.OverlaySheet {
    id: mySheet

    header: Kirigami.Heading {
        text: "My Overlay Sheet"
    }

    Controls.Label {
        Layout.fillWidth: true
        wrapMode: Text.WordWrap
        text: "Weeeeee, overlay sheet!"
    }
}
Overlay sheet with title text in its header area

We can also provide our overlay sheet with a footer . Footers in overlay sheets are quite flexible, but most often they are used to provide overlay sheets with some sort of quick interactive input similar to that provided by modal dialogs (e.g. buttons for "Apply", "Ok", "Cancel", "Close", etc.)

Los pies de página se definen de la misma manera que los encabezados:

Kirigami.OverlaySheet {
    id: mySheet

    header: Kirigami.Heading {
        text: "My Overlay Sheet"
    }

    footer: Controls.DialogButtonBox {
        standardButtons: DialogButtonBox.Close
        onRejected: mySheet.close()
    }

    Controls.Label {
        Layout.fillWidth: true
        wrapMode: Text.WordWrap
        text: "Weeeeee, overlay sheet!"
    }
}
Overlay sheet with a button in its footer area

Uso de vistas delegado/modelo

Dado que las hojas de superposición están diseñadas para mostrar contenido vertical, pueden resultar especialmente útiles cuando se usan junto a componentes del tipo ListViews . Cuando se muestra contenido más largo que la ventana de la aplicación, la hoja de superposición se vuelve desplazable:

Kirigami.OverlaySheet {
    id: mySheet

    ListView {
        model: 100
        implicitWidth: Kirigami.Units.gridUnit * 30
        delegate: Kirigami.BasicListItem {
            label: "Item in sheet " + modelData
        }
    }
}
Hoja superpuesta con una vista de lista