Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]MouseClick is always accepted

[SOLVED]MouseClick is always accepted

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    th.thielemann
    wrote on last edited by
    #1

    I created a Datamodel and a Listview to show it.
    I want to support:

    • completely show selected delegate
    • in-place edition of value in selected delegate
      Therefore I created a MouseArea to get current listView index. The click event shall not accepted. But it is always.
      I use Qt5.3 on Linux on x86.

    What do I wrong? Or how do I get the current index without a MouseArea?

    @import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Layouts 1.1
    import QmlOskPlugin 1.0

    Rectangle {
        id: root
        width: 480
        height: 272
    
        ListModel {
            id: personalData
            ListElement {
                dataLabel: "Firstname"
                dataValue: "Herbert"
            }
            ListElement {
                dataLabel: "Lastname"
                dataValue: "Roth"
            }
            ListElement {
                dataLabel: "Plays"
                dataValue: "Guitar"
            }
            ListElement {
                dataLabel: "Country"
                dataValue: "Germany"
            }
            ListElement {
                dataLabel: "Age"
                dataValue: "65"
            }
            ListElement {
                dataLabel: "Hobby"
                dataValue: "Walking"
            }
        }
    
        ScrollView {
            id: mainArea
            anchors.fill: parent
            clip: true
    
            ListView {
                id: listView
                anchors.fill: parent
                snapMode: ListView.SnapToItem
                model: personalData
    
                delegate:
                    Rectangle {
                        id: textInputElement
                        height: 50
                        width: parent.width
    
                        Text {
                            id: mlabel
                            width: parent.width / 2
                            font.pixelSize: 18;
                            text: dataLabel
                        }
                        TextInput {
                            id: minput
                            anchors.left: mlabel.right
                            width: parent.width / 2
                            font.pixelSize: 18;
                            text: dataValue
                        }
    
                        MouseArea {
                            anchors.fill: parent
                            propagateComposedEvents: true
                            onClicked: {
                                mouse.accepted = false
                                listView.currentIndex = index;
                                console.log("------------ currentIndex=" + listView.currentIndex);
                                listView.positionViewAtIndex(listView.currentIndex, ListView.Contain)
                            }
                        }
                    }
            }
        }
    }@
    
    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      bq.
      I want to support: – completely show selected delegate – in-place edition of value in selected delegate
      Therefore I created a MouseArea to get current listView index. The click event shall not accepted. But it is always.

      Can you explain a little bit more ?

      AFAIK, there's no other way than what you have used for getting currentIndex

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        th.thielemann
        wrote on last edited by
        #3

        Some details:
        The items are shown within the Listview. And I use a On Screen Keyboard (OSK) to edit item's value. The OSK shall be displayed at the bottom of the screen. But only in case a editable item (TextInput) is selected.
        This is working. But if a item is selected at the bottom of the screen, this item is hidden by the OSK. Therefore the Listview shall scroll until the item is visible above the OSK.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Isn't ListView.Center enough for you scenario ?

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            th.thielemann
            wrote on last edited by
            #5

            positionViewAtIndex is the solution. The trick is to find a event instead of MouseArea.onClicked to call it. I found it in the resize of the ListView. This is called everytime the OSK is shown/hidden. So it is solved.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved