Nesta página

Termostato

O exemplo “Termostato” demonstra como implementar diferentes designs dependendo do tamanho da janela.

Uma interface de usuário para um termostato doméstico, demonstrando como criar aplicativos responsivos em Qt Quick que se adaptam desde grandes telas de desktop até dispositivos móveis e pequenas telas embarcadas.

Tema de interface do usuário claro em tela vertical de celular Tema claro da interface do usuário em tela horizontal de celular

Tema de interface do usuário claro na tela do desktop

Tema escuro da interface do usuário em tela vertical de celular Tema escuro da interface do usuário em tela vertical de celular

Tema escuro da interface do usuário na tela do computador

Executando o exemplo

Você pode executar o exemplo a partir de:

Design responsivo

O aplicativo oferece suporte a diversos tamanhos de tela. Ele pode ser redimensionado dinamicamente quando o usuário altera o tamanho da janela, ou o aplicativo seleciona os tamanhos corretos com base na tela disponível em dispositivos móveis. O Constants.qml contém propriedades que especificam o tamanho da tela e controlam qual layout está em uso no momento:

    property bool isBigDesktopLayout: layout === Constants.Layout.Desktop
    property bool isSmallDesktopLayout: layout === Constants.Layout.SmallDesktop
    property bool isMobileLayout: layout === Constants.Layout.Mobile
    property bool isSmallLayout: layout === Constants.Layout.Small

Em ` App.qml`, as propriedades são vinculadas à altura e à largura da janela na inicialização do aplicativo:

    Component.onCompleted: {
        Constants.layout = Qt.binding(() => {
            let tall = window.height >= window.width
            if (window.width >= 1440 && window.height >= 520)
                return Constants.Layout.Desktop
            if (window.width >= 1024 && window.height >= 768)
                return Constants.Layout.SmallDesktop
            if (tall || (window.width >= 600 && window.height >= 380))
                return Constants.Layout.Mobile
            return Constants.Layout.Small
        })
    }

Os estados são então usados para controlar as propriedades dos componentes, como largura, altura, tamanho da fonte, posição e layout (coluna ou linha).

    states: [
        State {
            name: "bigDesktopLayout"
            when: Constants.isBigDesktopLayout
            PropertyChanges {
                target: statistics
                leftPadding: 53
                rightPadding: 53
                topPadding: 23
                bottomPadding: 43
            }
            PropertyChanges {
                target: scrollView
                isBackgroundVisible: false
                delegateWidth: 350
                delegateHeight: 182
                statisticsChartWidth: grid.width
                statisticsChartHeight: 647
            }
            PropertyChanges {
                target: grid
                width: 1100
            }
        },
        State {
            name: "smallDesktopLayout"
            when:  Constants.isSmallDesktopLayout
            PropertyChanges {
                target: statistics
                leftPadding: 53
                rightPadding: 53
                topPadding: 23
                bottomPadding: 43
            }
            PropertyChanges {
                target: scrollView
                isBackgroundVisible: false
                delegateWidth: 290
                delegateHeight: 182
                statisticsChartWidth: grid.width
                statisticsChartHeight: 541
            }
            PropertyChanges {
                target: grid
                width: 918
            }
        },
        State {
            name: "mobileLayout"
            when: Constants.isMobileLayout
            PropertyChanges {
                target: statistics
                leftPadding: 0
                rightPadding: 0
                topPadding: 0
                bottomPadding: 0
            }
            PropertyChanges {
                target: scrollView
                isBackgroundVisible: false
                delegateWidth: 327
                delegateHeight: 110
                statisticsChartWidth: 346
                statisticsChartHeight: 383
            }
        },
        State {
            name: "smallLayout"
            when: Constants.isSmallLayout
            PropertyChanges {
                target: statistics
                leftPadding: 0
                rightPadding: 0
                topPadding: 0
                bottomPadding: 0
            }
            PropertyChanges {
                target: scrollView
                isBackgroundVisible: true
                delegateWidth: 332
                delegateHeight: 90
                statisticsChartWidth: 420
                statisticsChartHeight: 240
            }
        }
    ]

Arquivos-fonte

Projeto de exemplo em @code.qt.io

Veja também Todos os exemplos do Qt XML e Exemplos e tutoriais doQt Quick .

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.