IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Quick Discussion :

[StackView] Test sur la page en cours


Sujet :

Qt Quick

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 60
    Par défaut [StackView] Test sur la page en cours
    Bonjour,
    je débute en Qt, j'ai repris le projet "touch" pour le modifier.
    Je souhaite simplement tester l'id d'un item d'un stask view et rendre visible suivant la page les boutons des toolsBars.
    Dans le but de faire des toolsBar personnaliser par page.

    Je n'arrive pas à tester l'id de la view courante et en fonction masquer ou pas les boutons.
    le stackview.get() renvoi souvent Null.
    j'ai essayé aussi en l'appelant avec stackview.deph-1. (1élement==> indice 0)


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
      ToolBar {
                    RowLayout {
                    id:row
                        function testIdView(str)
                        {
                            var current_item;
     
                            console.log("index : " + Stack.index );
                            console.log("stack active:" + Stack.Active)
     
                            if (Stack.index !== -1)
                             {
                                current_item = stackView.get(Stack.index,true);
                                console.log("depth : " + stackView.depth +" "+ current_item);
                                if (current_item !== null)
                                {
                                    console.log("id : " + current_item.id);
                                    if (current_item.id === str)
                                        return true;
                                    else
                                        return false;
                                    //Finsi
     
                                }
                            }
                            else
                             if (str === "initial")
                                 return true;
                              else
                                 return false;
                            //Finsi
     
     
     
                        }
     
     
     
     
                            anchors.fill: parent
                            ToolButton {
                                visible:row.testIdView("bouton")
                                iconSource:"images/toolbar.png"
                            }
     
     
                        }
                }


    dans ButtonPage.qml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.1
     
    Item {
        width: parent.width
        height: parent.height
        id:bouton
        property real progress: 0
        SequentialAnimation on progress {
            loops: Animation.Infinite
            running: true
            NumberAnimation {
                from: 0
     
    .....

    sortie:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Starting C:\Users\travel\Desktop\essai qt\build-touch-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\touch.exe...
    QML debugging is enabled. Only use this in a safe environment.
    qml: index : -1
    qml: stack active:3
    file:///C:/Qt/5.5/mingw492_32/qml/QtQuick/Controls/ToolBar.qml:142:9: QML Item: Binding loop detected for property "layoutHeight"
    file:///C:/Qt/5.5/mingw4 92_32/qml/QtQuick/Controls/ToolBar.qml:142:9: QML Item: Binding loop detected for property "layoutHeight"
    qrc:/main.qml:104:13: QML ToolBar: Binding loop detected for property "implicitHeight"
    qrc:/main.qml:104:13: QML ToolBar: Binding loop detected for property "width"
    qrc:/main.qml:104:13: QML ToolBar: Binding loop detected for property "width"
    C:\Users\travel\Desktop\essai qt\build-touch-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\touch.exe exited with code 0

  2. #2
    Rédacteur/Modérateur

    Avatar de Jiyuu
    Homme Profil pro
    Développeur amateur
    Inscrit en
    Janvier 2007
    Messages
    2 456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur amateur
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 2 456
    Billets dans le blog
    15
    Par défaut


    (on va passer ça sur la fatigue de la journée) Désolé, mais je ne suis pas sûr de bien comprendre par "tester l'id de la view".

    Il me semble comprendre que ce que tu veux dire c'est : si je vois ça alors j'affiche ça, ce qui en QML revient à dire "si composant1 est visible alors composant2 l'est aussi":
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    composant2.visible = composant1.visible
    .

    Mais je me trompe peut-être.

    ++

    J
    Initiation à Qt Quick et QML : Partie 1 - Partie 2
    En cas de besoin, pensez à la
    Mon site et mes tutoriaux sur Developpez.com
    Pas de question technique par MP... Les forums sont là pour ça

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 60
    Par défaut
    comme décrit en haut je souhaite mettre une toolsbar en haut du stackview et afficher ou non certain bouton pour créer la toolsbar.
    j'avais pensé à tester la page en cours de stackview et tester son id ou le nom de l'item.
    je ne sais pas faire.

  4. #4
    Rédacteur/Modérateur

    Avatar de Jiyuu
    Homme Profil pro
    Développeur amateur
    Inscrit en
    Janvier 2007
    Messages
    2 456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur amateur
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 2 456
    Billets dans le blog
    15
    Par défaut


    D'après la doc il y a une propriété currentItem, donc je suppose une méthode onCurrentItemChanged.

    As-tu essayé quelque chose qui ressemble à ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    StackView {
        // ... tes différentes views
        onCurrentItemChanged{
            if (currentItem.objectName === "toto"){
                // ... ce que je dois faire
            }
            else if (currentItem.objectName === "titi") {
                // ...
            }
         }
    }
    Initiation à Qt Quick et QML : Partie 1 - Partie 2
    En cas de besoin, pensez à la
    Mon site et mes tutoriaux sur Developpez.com
    Pas de question technique par MP... Les forums sont là pour ça

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 60
    Par défaut
    merci j'ai avancé mais dès que je tappe les lignes que je veux, qt creator ce ferme ...
    un projet exemple fonctionne mais quand je tappe ce que je veux l'éditeur plante.
    j'ai réinstallé deux fois, j'ai pas de problème particulier d'habitude.

    j'ai donc adapter mon code avec le currentitem.objectName

    il me semble que le test sur la string est mal interpreter, l'objectName est bon , str est bon , mais va dans le false.(sur windows j'ai vu ca)
    sur mon mac les lignes ci dessous plante totelement Qt a l'édition.(il se ferme)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
     
    /****************************************************************************
    **
    ** Copyright (C) 2015 The Qt Company Ltd.
    ** Contact: http://www.qt.io/licensing/
    **
    ** This file is part of the examples of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:BSD$
    ** You may use this file under the terms of the BSD license as follows:
    **
    ** "Redistribution and use in source and binary forms, with or without
    ** modification, are permitted provided that the following conditions are
    ** met:
    **   * Redistributions of source code must retain the above copyright
    **     notice, this list of conditions and the following disclaimer.
    **   * Redistributions in binary form must reproduce the above copyright
    **     notice, this list of conditions and the following disclaimer in
    **     the documentation and/or other materials provided with the
    **     distribution.
    **   * Neither the name of The Qt Company Ltd nor the names of its
    **     contributors may be used to endorse or promote products derived
    **     from this software without specific prior written permission.
    **
    **
    ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
     
    import QtQuick 2.2
    import QtQuick.Controls 1.2
    import "content"
    import QtQuick.Layouts 1.1
     
    ApplicationWindow {
        visible: true
        width: 800
        height: 1280
     
        Rectangle {
            color: "#212126"
            anchors.fill: parent
        }
     
        toolBar: BorderImage {
            border.bottom: 8
            source: "images/toolbar.png"
            width: parent.width
            height: 100
     
            Rectangle {
                id: backButton
                width: opacity ? 60 : 0
                anchors.left: parent.left
                anchors.leftMargin: 20
                opacity: stackView.depth > 1 ? 1 : 0
                anchors.verticalCenter: parent.verticalCenter
                antialiasing: true
                height: 60
                radius: 4
                color: backmouse.pressed ? "#222" : "transparent"
                Behavior on opacity { NumberAnimation{} }
                Image {
                    anchors.verticalCenter: parent.verticalCenter
                    source: "images/navigation_previous_item.png"
                }
                MouseArea {
                    id: backmouse
                    anchors.fill: parent
                    anchors.margins: -10
                    onClicked: stackView.pop()
                }
            }
     
            Text {
                font.pixelSize: 42
                Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
                x: backButton.x + backButton.width + 20
                anchors.verticalCenter: parent.verticalCenter
                color: "white"
                text: "Widget Gallery"
            }
     
     
            ToolBar {
    		id:lignebouton
     
           function testview(str)
            {
                if (stackView.depth >0)
                {
                if (stackView.currentItem.objectName === str)
                  return true;
                else
                    return false;
                }
            }
     
                    RowLayout {
                        anchors.fill: parent
                        ToolButton {
                            iconSource: "images/toolbar.png"
                            visible:lignebouton.testView("bouton")
                        }
                    }
            }
     
     
        }
     
        ListModel {
            id: pageModel
            ListElement {
                title: "Buttons"
                page: "content/ButtonPage.qml"
            }
            ListElement {
                title: "Sliders"
                page: "content/SliderPage.qml"
            }
            ListElement {
                title: "ProgressBar"
                page: "content/ProgressBarPage.qml"
            }
            ListElement {
                title: "Tabs"
                page: "content/TabBarPage.qml"
            }
            ListElement {
                title: "TextInput"
                page: "content/TextInputPage.qml"
            }
            ListElement {
                title: "List"
                page: "content/ListPage.qml"
            }
        }
     
        StackView {
            id: stackView
            anchors.fill: parent
            // Implements back key navigation
            focus: true
            Keys.onReleased: if (event.key === Qt.Key_Back && stackView.depth > 1) {
                                 stackView.pop();
                                 event.accepted = true;
                             }
     
            initialItem: Item {
                width: parent.width
                height: parent.height
                ListView {
                    model: pageModel
                    anchors.fill: parent
                    delegate: AndroidDelegate {
                        text: title
                        onClicked: stackView.push(Qt.resolvedUrl(page))
                    }
                }
            }
        }
     
    }

  6. #6
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 60
    Par défaut
    sa fonctionne avec le projet ici pas de bug (jamais confondu stackView et StackView......)
    sa n'explique pas les plantages de qtcreator sur l'autre fichier

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    /****************************************************************************
    **
    ** Copyright (C) 2015 The Qt Company Ltd.
    ** Contact: http://www.qt.io/licensing/
    **
    ** This file is part of the examples of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:BSD$
    ** You may use this file under the terms of the BSD license as follows:
    **
    ** "Redistribution and use in source and binary forms, with or without
    ** modification, are permitted provided that the following conditions are
    ** met:
    **   * Redistributions of source code must retain the above copyright
    **     notice, this list of conditions and the following disclaimer.
    **   * Redistributions in binary form must reproduce the above copyright
    **     notice, this list of conditions and the following disclaimer in
    **     the documentation and/or other materials provided with the
    **     distribution.
    **   * Neither the name of The Qt Company Ltd nor the names of its
    **     contributors may be used to endorse or promote products derived
    **     from this software without specific prior written permission.
    **
    **
    ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
     
    import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Layouts 1.2
    import "content"
     
    ApplicationWindow {
        visible: true
        width: 800
        height: 1280
     
        Rectangle {
            color: "#212126"
            anchors.fill: parent
        }
     
        toolBar: BorderImage {
            border.bottom: 8
            source: "images/toolbar.png"
            width: parent.width
            height: 200
            Rectangle {
                id: backButton
                width: opacity ? 60 : 0
                anchors.left: parent.left
                anchors.leftMargin: 20
                opacity: stackView.depth > 1 ? 1 : 0
                anchors.verticalCenter: parent.verticalCenter
                antialiasing: true
                height: 60
                radius: 4
                color: backmouse.pressed ? "#222" : "transparent"
                Behavior on opacity { NumberAnimation{} }
                Image {
                    anchors.verticalCenter: parent.verticalCenter
                    source: "images/navigation_previous_item.png"
                }
                MouseArea {
                    id: backmouse
                    anchors.fill: parent
                    anchors.margins: -10
                    onClicked: stackView.pop()
                }
            }
     
            Text {
                id :textNav
                font.pixelSize: 42
                Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
                x: backButton.x + backButton.width + 20
                anchors.verticalCenter: parent.verticalCenter
                color: "Red"
                text: "Menu"
            }
     
            Rectangle{
                id:toolsbarIcone
                width:parent.width
                color:"black"
                height:30
                anchors.top: textNav.bottom
                border.color: "white"
                border.width: 1
     
                ToolBar {
                    RowLayout {
                    id:row
                        function testIdView(str)
                        {
     
                            console.log(str,stackView.currentItem.objectName,stackView.depth )
                            if ((stackView.depth  > 0) && (stackView.currentItem.objectName === str))
                            {
                                console.log("true")
                                return true;
                            }
                            else
                            {
                                 console.log("false")
                                return false;
                        }
                        }
     
     
     
     
                            anchors.fill: parent
                            ToolButton {
                                visible:row.testIdView("bouton")
                                iconSource:"images/toolbar.png"
                            }
     
     
                        }
                }
     
            }
     
        }
     
        ListModel {
            id: pageModel
            ListElement {
                title: "Buttons"
                page: "content/ButtonPage.qml"
            }
            ListElement {
                title: "Sliders"
                page: "content/SliderPage.qml"
            }
            ListElement {
                title: "ProgressBar"
                page: "content/ProgressBarPage.qml"
            }
            ListElement {
                title: "Tabs"
                page: "content/TabBarPage.qml"
            }
            ListElement {
                title: "TextInput"
                page: "content/TextInputPage.qml"
            }
            ListElement {
                title: "List"
                page: "content/ListPage.qml"
            }
        }
     
        StackView {
            id: stackView
            anchors.fill: parent
            // Implements back key navigation
            focus: true
            Keys.onReleased: if (event.key === Qt.Key_Back && stackView.depth > 1) {
                                 stackView.pop();
                                 event.accepted = true;
                             }
            onCurrentItemChanged:{
     
            }
            initialItem: Item {
                width: parent.width
                height: parent.height
                ListView {
                    model: pageModel
                    anchors.fill: parent
                    delegate: AndroidDelegate {
                        text: title
                        onClicked: stackView.push(Qt.resolvedUrl(page))
     
                    }
                }
            }
        }
     
    }

  7. #7
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 60
    Par défaut
    un problème récurrent aussi, il faut nettoyer souvent le projet pour que la compile fonctionne?
    souvent il prend pas en compte les modifs sur "Executer"... vous avez une solution? c'est assez énervant.

Discussions similaires

  1. Positionnement ascenceur sur la page en cours
    Par vince29 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 09/10/2012, 10h52
  2. Test sur menu ouvrant au chargement de la page
    Par yoshï dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 16/04/2008, 11h53
  3. Réponses: 2
    Dernier message: 16/12/2007, 20h55
  4. Test sur actualisation page Web
    Par djy023 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 04/11/2006, 17h42
  5. [XLS-FO] Test sur le numero de page
    Par serwol dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 10/10/2005, 13h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo