Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to select more than one delegates in listview



  • Hi all,
    i have a listview with readonly text delegates, how can i visually select more than one delegates by pressing and moving the mouse over multiple delegates? E.g. there are multiple chat messages and i want to select some of them to be able to copy them. Is there any way to do that?

    Thanks in advance.





  • @jd42 why do you want to select more than one delegate? Do you want to delete particular or group of index from list view or you want to copy that index?

    First of all you have to implement Pressandhold and Onclick functionality on mouseArea and specify z=-1
    import QtQuick 2.7
    import QtQuick.Controls 1.4
    import QtQuick.Controls 2.1

    import "Utilitiesforarray.js" as Utilsarray
    property bool flag: false
    MouseArea
    {
    id:mouseareaforselecting
    anchors.fill: parent
    z:-1
    onPressAndHold:
    {
    //initially flag becomes flase, after PressandHold the flag becomes true
    if(flag===false)
    {
    patientdetailslist.currentIndex=index
    rectfordelegate.color="sky blue"
    flag=true;
    Utilsarray.pushIndex(index); //storing index in array, i have method called pushIndex in Utilitiesforarray.js file
    }
    }
    //now you can select how many delegates you want
    onClicked:
    {
    if(flag===true)
    {
    //store the index values into JavaScript array
    }
    else
    {
    //do your stuff
    }
    }


Log in to reply