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. selectable item in listview while dragging is enable
Forum Updated to NodeBB v4.3 + New Features

selectable item in listview while dragging is enable

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 2 Posters 2.0k 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.
  • AlienA Offline
    AlienA Offline
    Alien
    wrote on last edited by
    #1

    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 bit

    I appreciate any idea.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fheanor
      wrote on last edited by Fheanor
      #2
      ...
      MouseArea {
                  id: dragArea
                  ...
                  onPressed : {
                             console.log(name + " is selected")
                 }
                 ...
      }
      
      AlienA 1 Reply Last reply
      0
      • F Fheanor
        ...
        MouseArea {
                    id: dragArea
                    ...
                    onPressed : {
                               console.log(name + " is selected")
                   }
                   ...
        }
        
        AlienA Offline
        AlienA Offline
        Alien
        wrote on last edited by Alien
        #3

        @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?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fheanor
          wrote on last edited by Fheanor
          #4

          Replace onPressAndHold by onPressed 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"
          }
          
          AlienA 1 Reply Last reply
          0
          • F Fheanor

            Replace onPressAndHold by onPressed 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"
            }
            
            AlienA Offline
            AlienA Offline
            Alien
            wrote on last edited by Alien
            #5

            @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?

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Fheanor
              wrote on last edited by
              #6

              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 using onPressed function, your item will be highlighted

              AlienA 1 Reply Last reply
              0
              • F Fheanor

                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 using onPressed function, your item will be highlighted

                AlienA Offline
                AlienA Offline
                Alien
                wrote on last edited by
                #7

                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

                F 1 Reply Last reply
                0
                • AlienA Alien

                  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

                  F Offline
                  F Offline
                  Fheanor
                  wrote on last edited by
                  #8

                  @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
                  ...
                  }
                  
                  AlienA 1 Reply Last reply
                  1
                  • F Fheanor

                    @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
                    ...
                    }
                    
                    AlienA Offline
                    AlienA Offline
                    Alien
                    wrote on last edited by
                    #9

                    Dear @Fheanor,
                    Thank you so much that's the correct solution.
                    but why you said "It seems that this example is quite buggy"?

                    F 1 Reply Last reply
                    0
                    • AlienA Alien

                      Dear @Fheanor,
                      Thank you so much that's the correct solution.
                      but why you said "It seems that this example is quite buggy"?

                      F Offline
                      F Offline
                      Fheanor
                      wrote on last edited by Fheanor
                      #10

                      @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 ;-)

                      AlienA 1 Reply Last reply
                      0
                      • F Fheanor

                        @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 ;-)

                        AlienA Offline
                        AlienA Offline
                        Alien
                        wrote on last edited by
                        #11

                        @Fheanor
                        Oh OK
                        Thanks again

                        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