Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget elements sorting using drag&drop
Forum Updated to NodeBB v4.3 + New Features

QListWidget elements sorting using drag&drop

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.3k 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.
  • C Offline
    C Offline
    Chiz_
    wrote on last edited by
    #1

    I have QListView. I added elements in there using @new QListWidgetItem(text, qlwElements);@. Later I will use icons for elements, so I plan to use another code @QListWidgetItem *newItem = new QListWidgetItem(text, qlwElements);
    newItem->setIcon(iconPath);@
    Question: how to sort elements using drug and drop functionality and after that add some more elements?
    I want to add three elements - 1, 2, 3. Then drag first one (1) to the end, so they will be 2, 3, 1. And then I want to add element 4. So after adding fourth element I want 2, 3, 1, 4.
    Now I have 1,2,3,4 after adding fourth element.
    Is there some functionality to "auto sort elements" after drop? Or where, when and in what method I can get info about where user drop element?

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      there is a sortingenabled property that you can set to true to do this automatically

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chiz_
        wrote on last edited by
        #3

        [quote author="chetankjain" date="1297848972"]there is a sortingenabled property that you can set to true to do this automatically[/quote]

        It sorts wonderful! But I need sorting in another way.
        I need to sort my Model somehow and then View will sort elements in proper way. But how I can get know how user sort elements in View? So I can resort elements in Model and then say View resort View. And it will sort elements in that way as user set.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Darryl DSouza
          wrote on last edited by
          #4

          What do you mean by "I need to sort my Model somehow". The sort order is always stored and Qt takes care of that for you. When an item is added to the model, does'nt matter whether drag and drop or some other way. Sorting is always retained. Only important part is that your model must know when the data is added.

          Darryl D'Souza

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chiz_
            wrote on last edited by
            #5

            [quote author="Darryl DSouza" date="1297862915"]What do you mean by "I need to sort my Model somehow".[/quote]
            I have list of my own objects. When I click add button I create object, add it to list and add QListViewItem to QListView with proper text to show user that he add element to list.
            All elements have their own place in my list and in QListView. When user sort them in UI I want to know which element now on what position.
            User drag first element to the end and now it isn't on first place. Now it at the end of list. But I can see it only in UI. I don't know how to get this info in code.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Darryl DSouza
              wrote on last edited by
              #6

              Did you check whether you get the signal from the view void QAbstractItemView::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) or did you try to check the signal void indexesMoved ( const QModelIndexList & indexes ) ?
              You will know which item is moved where?

              Darryl D'Souza

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chiz_
                wrote on last edited by
                #7

                I solve this issue in other way. Not really good, but acceptable.
                I change view mode from Icon to List and that is it.
                Maybe in future versions I will reimplement.
                Thanks, Darryl DSouza!

                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