Русскоязычный портал о QML и QtQuick, QmlPortal What the duck
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум QML » QML форум » Вопросы по QML » Поверка состояния елементов из других модулей (Поверка состояния елементов из других модулей)
Поверка состояния елементов из других модулей
RomkoДата: Вторник, 27.09.2011, 23:47 | Сообщение # 1
Постоялец
Группа: Проверенные
Сообщений: 22
Награды: 0
Репутация: 2
Статус: Offline
Скажите пожалуйста каким образом можно управлять или проверять состояние элемента (opacity или mouseArea.pressed) который находиться в цепочке модулей, но через 1?

Допустим у нас есть один модуль (№1), его используют в другом модуле (№2), а модуль (№2) используют в модуле (№3). И мне нужно из модуля (№3) проверить нажата ли mouseArea в модуле (№1)

Заранее большое спасибо.

Добавлено (20.09.2011, 22:49)
---------------------------------------------
Main.qml

Code
import QtQuick 1.0

Rectangle {
     width: 600
     height: 402
     color: "lightgrey"

     Mod1{id: progress
         anchors.horizontalCenter: parent.horizontalCenter
         anchors.verticalCenter: parent.verticalCenter}

         Rectangle {id: disp
             x: 100; y: 29
             width: 400; height: 97
             color: "#8d6565"
             opacity: 0
         }
          
         states: [
             State {
                 name: "name"; when: /*siledeArea in Mod2 .pressed*/
                 PropertyChanges {target: disp; opacity: 1}
             }
         ]
}


Mod1.qml

Code
import QtQuick 1.0

Rectangle {
     id: panel
     width: 400
     height: 100
     color: "lightgreen"

     Mod2{
         anchors.horizontalCenter: parent.horizontalCenter
         anchors.verticalCenter: parent.verticalCenter}
}


Mod2.qml

Code


import QtQuick 1.0

Rectangle {
     width: 250
     height: 50
     color: "#d11818"

     Rectangle {
         id: cont
         x: 25
         y: 18
         width: 200
         height: 15
         color: "#ffffff"

         MouseArea {
             id: mouse_area1
             anchors.fill: parent
             onClicked: slider.x = mouse.x - 5
         }

         Rectangle {
             id: slider
             x: 0
             y: -4
             width: 10
             height: 23
             color: "#030202"

             MouseArea {
                 id: sliderArea
                 anchors.fill: parent

                 drag.target: slider
                 drag.axis: Drag.XAxis
                 drag.minimumX: -slider.width/2
                 drag.maximumX: cont.width - slider.width/2
             }
         }
     }

     }


Ка то так, в main.qml должен быть не обязательно state для изменения opacity)

Добавлено (27.09.2011, 23:47)
---------------------------------------------
Единственное что мне пока пришло в голову, это использование глобальных переменных при помощи javascript.
Но не знаю выход ли это, нормально ли только ради этого добавлять js файл, и не знаю не будет ли потом каких то новых проблем.

 
CYANДата: Воскресенье, 02.10.2011, 15:08 | Сообщение # 2
Администратор
Группа: Администраторы
Сообщений: 21
Награды: 1
Статус: Offline
Как вариант - можно свойтво протащить через псевдоним (property alias):

Main.qml
Code
import QtQuick 1.0

Rectangle {
     width: 600
     height: 402
     color: "lightgrey"

     Mod1{
         id: progress
         anchors.horizontalCenter: parent.horizontalCenter
         anchors.verticalCenter: parent.verticalCenter
     }

     Rectangle {
         id: disp
         x: 100; y: 29
         width: 400; height: 97
         color: "#8d6565"
         opacity: (1-progress.mod2Inst.sliderX/195)
     }

     states: [
         State {
             name: "name";
             when: (disp.opacity!=(1-progress.mod2Inst.sliderX/195))
             PropertyChanges {target: disp; opacity: (1-progress.mod2Inst.sliderX/195)}
         }
     ]
}


Mod1.qml
Code
import QtQuick 1.0

Rectangle {
     width: 400
     height: 100
     color: "lightgreen"

     property alias mod2Inst: mod2Instance

     Mod2{
         id: mod2Instance
         anchors.horizontalCenter: parent.horizontalCenter
         anchors.verticalCenter: parent.verticalCenter}
}


Mod2.qml
Code
import QtQuick 1.0

Rectangle {
     width: 250
     height: 50
     color: "#d11818"

     property alias sliderX: slider.x

     Rectangle {
         id: cont
         x: 25
         y: 18
         width: 200
         height: 15
         color: "#ffffff"

         MouseArea {
             id: mouse_area1
             anchors.fill: parent
             onClicked: slider.x = mouse.x - 5
         }

         Rectangle {
             id: slider
             x: 0
             y: -4
             width: 10
             height: 23
             color: "#030202"

             MouseArea {
                 id: sliderArea
                 anchors.fill: parent

                 drag.target: slider
                 drag.axis: Drag.XAxis
                 drag.minimumX: -slider.width/2
                 drag.maximumX: cont.width - slider.width/2
             }
         }
     }

}
 
Форум QML » QML форум » Вопросы по QML » Поверка состояния елементов из других модулей (Поверка состояния елементов из других модулей)
  • Страница 1 из 1
  • 1
Поиск: