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. [Solved] QListView: ReOrdering list Items using Drag and Drop.
Forum Updated to NodeBB v4.3 + New Features

[Solved] QListView: ReOrdering list Items using Drag and Drop.

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 8.5k 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.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    I am implementing the Drag and Drop functionality in a listView, I implemented the methods given in the documentation , the drag and drop works correctly , However the listitem are not ordered properly. I have also subclassed QStandardItemModel and overridden

    @Qt::ItemFlags flags(const QModelIndex &index) const;
    Qt::DropActions supportedDropActions() const;@

    I searched for the same, but couldnt get any specific detail regarding the implementation.

    Any help will be highly appreciated.

    Thanks.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      if you want to use it for reordering, I think you have to implement the move for drag and drop.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Come on Sam, are you kidding me?

        https://qt-project.org/forums/viewthread/20627/
        https://qt-project.org/forums/viewthread/20762/
        https://qt-project.org/forums/viewthread/20684/
        https://qt-project.org/forums/viewthread/20584/

        and now again a new topic on the same issue.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          Do I need to implement this for my listView or for the model ? I have a custom ListView and a custom model that inherits QStandardItemModel.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            I am sorry Andre, I dont want to create a new thread, I just got a bit confused . Should I use a single topic for an entire requirement or should I seperate each topic as I did here.

            I dont have any problem if all the topics are merged at a single place. I cant delete all the other threads that I have created, If it is against the rules of the forum I humbly request you (moderator) to take necessary actions/delete the other topics as well.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              You keep on making topics for aspects of your problem, without ever giving the big picture. That is very annoying. It seems that you want to achieve some bigger goal, but you have no clue how to do it. Or rather, you are just trying different approaches and ask about your issues with those, instead of asking about your real problem. Rather like "this":http://mywiki.wooledge.org/XyProblem fenomenon. This is also an "item":http://www.catb.org/esr/faqs/smart-questions.html#goal in the FAQ on how to ask smart questions.

              So: first be clear about what you are trying to achieve, then discribe how you tried to achieve that, and what your problems were with that approach (or those approaches). Then ask for suggestions on how to solve your actual issue.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                Thanks for the explanations, I understand that I created the similar XY problem specified in the link. I'll try to ask questions that are well prepared, easily understood and less annoying.

                For the actual question i.e reordering the listview items using drag and drop, I have implemented the code that runs as expected. I'll update the code after a while.

                Thanks

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  So far the drag and drop functionality works as expected and the item are arranged properly in the listView. I have also tried to implement a scrolling functionality that scrolls the listView up/down based on the visible row(top row n bottom row) in the viewport->rect() while dragging an item.

                  I am changing the verticalScrollBar value inside the dragMoveEnter() event

                  @QScrollBar *scroll = verticalScrollBar();
                  if (currentRow == topRow)
                  {
                  scroll->setValue(scroll->value() -1);

                  } else if (currentRow == bottomRow)
                  {
                  scroll->setValue(scroll->value() +1);
                  }@

                  where currentRow is the row where the mouse position is while dragging the item.

                  However the scroll bar value changes only on mouseMove / dragMove , means if i have 1000 items in the list then at the last row in the visible viewport() i have to keep on moving the mouse to scroll down, But I want to create a functionality like if the item is dragged and is at the top/bottom row in the visible region then the scroll bar should move up/down automatically.

                  Is it possible to get continuous events or a sensitve area that fires the signal continuously if mouseOver?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sam
                    wrote on last edited by
                    #9

                    Ok one more question,

                    My ListView contains a customWidget which is added using setIndexWidget(),where customWidget has few components like a combobox + lineEdits + labels , So far I have installed eventFilter for my customWidget that works fine, How can i set eventFilters for my listView so that If any widget on the customWidget is selected then the currentIndex/currentItem in the listView gets highlighted/selected.

                    Thanks

                    Edit :- Implemented using signal, slots and eventFilters().

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nasit.bhavin
                      wrote on last edited by
                      #10

                      Mr Andre,

                      I am unable to drag and drop with link action. If understand well, with link action, we can drag the references of the items so that any changes made in the source items will reflect the destination items(which is my requirement). Unfortunately, I couldn't succeed. If this is the big topic then i would open a new thread.

                      Thanks.

                      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