[SOLVED]MouseClick is always accepted
-
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.0Rectangle { 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) } } } } } }@
-
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
-
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. -
Isn't ListView.Center enough for you scenario ?
-
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.