Solved selectable item in listview while dragging is enable
-
Hi,
How do I add select feature to "QML Dynamic View Ordering Tutorial 3" example and get the selected item values?
SDK : QT 5.8.0
Compiler: MinGW 32 bitI appreciate any idea.
-
... MouseArea { id: dragArea ... onPressed : { console.log(name + " is selected") } ... }
-
@Fheanor ,
Thanks for your reply but I mean how to highlight the element(just single selection(one element per time)) when user tap or click on it? -
Replace
onPressAndHold
byonPressed
should do what you want.So you will have :
onPressed: held = true
If you want to understand what they do, they just change the color of the selected Item when
held = true
.Code :
color: dragArea.held ? "lightsteelblue" : "white"
Meaning if you have trouble with this syntax:
if (dragArea.held == true) { color = "lightsteelblue" } else { color = "white" }
-
@Fheanor ,
I need both drag and select feature sometime user needs to select an item and some other time he want to drag one item to other position so I need both now what should I do? -
I don't understand what do you mean. Can you explain it more clearly.
If you select an item or if you drag it, by usingonPressed
function, your item will be highlighted -
Dear @Fheanor ,
This app is just for dragging items to the other position if you hold one item for about 2 second you are be able to move the item I need this feature for my app also I need a way in which users can select one item by just on click on it.
When user click on one item I want to highlight the item to show the user the item selected now and be ready for some changes.
that's the actual problem -
@Alien So if you just click on the Item, you just have to change the color.
... MouseArea { id: dragArea property bool selected : false ... onClicked : { if(view.currentItem != null) view.currentItem.selected = false view.currentItem = dragArea selected = true } ... Rectangle { ... color: dragArea.held ? "lightsteelblue" : dragArea.selected ? "yellow" : "white" ... } } .... ListView { id: view property var currentItem: null ... }
-
Dear @Fheanor,
Thank you so much that's the correct solution.
but why you said "It seems that this example is quite buggy"? -
@Alien You are welcome :) `
I was wrong sorry, I didn't press enough my mouse, so I thought
onPressAndHold
function was not working but it does, I just had to wait 2 sc ;-) -
@Fheanor
Oh OK
Thanks again