QML список просмотра чтения текущей и сенсорной области - PullRequest
1 голос
/ 20 февраля 2012

У меня есть эта проблема. У меня есть просмотр списка, который я заполняю из кода QT, но я хочу, чтобы просмотр списка был сенсорным, поэтому при нажатии я действительно могу выбрать определенный элемент. Теперь я могу перемещаться со стрелками вверх и вниз, но при переносе на Android это не работает. Я пытался добавить область мыши, но я не могу заставить ее работать со списком. Так что это проблема № 1 и второй вопрос о получении выбранного элемента. Поэтому, когда я нажимаю на определенный элемент в списке, я хочу прочитать данные из него.

Вот кусок моего кода, если вам нужно больше, просто дайте мне знать:

ListView {
         id: listview1
         x: 0
         y: 82
         width: 395
         height: 942
         visible: true
         keyNavigationWraps: false
         boundsBehavior: Flickable.DragAndOvershootBounds
         opacity: 1
         maximumFlickVelocity: 2500
         anchors.leftMargin: 0
         highlightMoveSpeed: 489
         contentWidth: 0
         preferredHighlightEnd: 2
         spacing: 5
         highlightRangeMode: ListView.NoHighlightRange
         snapMode: ListView.SnapToItem
         anchors.bottomMargin: 0
         anchors.rightMargin: 179
         anchors.topMargin: 82
              anchors.fill: parent
              model: myModel
              delegate:Component {
                 // id: contactDelegate
                  Item {
                      property variant myData: model
                      width: 450; height: 90
                      Column {
                          Text { text: '<b>ID: </b> ' + id_korisnika ; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 8 }
                          Text { text: '<b>Ime: </b> ' + ime_korisnika ; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 8 }
                          Text { text: '<b>Prezime: </b> ' + prezime_korisnika; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 8 }
                          Text { text: '<b>Broj telefona: </b> ' + broj_korisnika ; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 8 }
                          Text { text: '<b>Adresa: </b> ' + adresa_korisnika ; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 8 }
                      }
                  }
              }
             // delegate: contactDelegate
              highlight: Rectangle {color:"black"; radius: 5; opacity: 0.7 }
              focus: true

          }

          BorderImage {
              id: border_image1
              x: 0
              y: 0
              width: 501
              height: 81
              source: "slike/naslov.png"

              MouseArea {
                  id: mouse_area1
                  x: 0
                  y: 81
                  anchors.fill: parent
              }
          }

          Rectangle {
              id: rectangle1
              x: 395
              y: 82
              width: 100
              height: 718
              gradient: Gradient {
                  GradientStop {
                      position: 0
                      color: "#f3eeee"
                  }

                  GradientStop {
                      position: 1
                      color: "#621717"
                  }
              }

              Image {
                  id: image1
                  x: 2
                  y: 314
                  width: 100
                  height: 100
                  source: "slike/Button-Next-icon.png"

              }
          }

          //dodaj korisnika
          Flipable {
              id: flipable
              x: 401
              y: 98
              width: 87
              height: 70
              property bool flipped: false

                   front: Image { x: 0; y: 0; width: 60; height: 58;  source: "slike/dodaj_korisnika.png"; anchors.centerIn: parent }
                   back: Image { x: 0; y: 0; width: 60; height: 58; source: "slike/accept.png"; anchors.centerIn: parent }

                   transform: Rotation {
                       id: rotation
                       origin.x: flipable.width/2
                       origin.y: flipable.height/2
                       axis.x: 1; axis.y: 0; axis.z: 0     // set axis.y to 1 to rotate around y-axis
                       angle: 0    // the default angle
                   }

                   states: State {
                       name: "back"
                       PropertyChanges { target: rotation; angle: 180 }
                       when: flipable.flipped
                   }

                   transitions: Transition {
                       NumberAnimation { target: rotation; property: "angle"; duration: 500 }
                   }

                   MouseArea {
                       x: 7
                       y: 9
                       width: 73
                       height: 76
                       anchors.rightMargin: 7
                       anchors.leftMargin: 7
                       anchors.topMargin: 9
                       anchors.bottomMargin: 9
                       hoverEnabled: false
                       anchors.fill: parent
                       onClicked: {
                           if(Varijabla.unos_korisnika==1)
                           {   window.state == 'State1' ? window.state = "" : window.state = 'State1'; flipable.flipped = !flipable.flipped; Varijabla.povecaj() }
                           else if(Varijabla.unos_korisnika==2)
                           {
                               window.state == "" ? window.state = 'State1' : window.state = ""; flipable.flipped = !flipable.flipped; Varijabla.reset();

                              funkcije.dodaj_korisnika(text_input1.text,text_input2.text,text_input3.text,text_input4.text);
                           }
                   }
                }

Доступны текстовые переменные:

    TextInput {
        id: text_input1
        x: 59
        y: 131
        width: 80
        height: 20
        font.pixelSize: 12
        opacity: 0
    }

    TextInput {
        id: text_input3
        x: 59
        y: 246
        width: 80
        height: 20
        font.pixelSize: 12
        opacity: 0
    }

    TextInput {
        id: text_input4
        x: 59
        y: 305
        width: 80
        height: 20
        font.pixelSize: 12
        opacity: 0
    }

    TextInput {
        id: text_input2
        x: 59
        y: 190
        width: 80
        height: 20
        font.pixelSize

: 12
    opacity: 0
}

1 Ответ

2 голосов
/ 21 февраля 2012

MouseArea внутри делегата должно работать нормально, объявлять сигнал в вашем ListView и излучать его из делегата / MouseArea.Вы можете выдавать произвольные данные, но в большинстве случаев достаточно модельного индекса:

ListView {
    signal itemSelected(int index)
    delegate: Rectangle {
        MouseArea {
            anchors.fill: parent
            onClicked: itemSelected(model.index)
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...