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. QListView icons movement

QListView icons movement

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.0k Views
  • 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
    chabo
    wrote on last edited by A Former User
    #1

    I would like to forbid movement of icons in the view but dragging to other views should stay enabled. Is there a way to achieve this?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      setAcceptDrops(false);
      might do it.
      Else DragDropMode set to DragOnly

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

        Hi,
        sorry, I didn't mention it, but dropping to view should be enabled.
        I have QListView attached to QFileSystemModel. I would like to drag&drop files from/to this view, but I I want to forbid moving of icons within the view only(changing their positions in view).

        possible solution could be: returns icon to its original position if it was dropped to the same view and it was not dropped to some element(I want overwrite file if it was dropped to other file or copy file to folder if it was dropped to folder)

        mrjjM 1 Reply Last reply
        0
        • C chabo

          Hi,
          sorry, I didn't mention it, but dropping to view should be enabled.
          I have QListView attached to QFileSystemModel. I would like to drag&drop files from/to this view, but I I want to forbid moving of icons within the view only(changing their positions in view).

          possible solution could be: returns icon to its original position if it was dropped to the same view and it was not dropped to some element(I want overwrite file if it was dropped to other file or copy file to folder if it was dropped to folder)

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @chabo said:
          If you have override then dropEvent/dropEnter
          you can check for the source of the event.
          if event->source() == this then reject
          else accept
          Yes same as your idea, but just forbid the actual drop so
          no need moving it back.

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

            Thank you very much.

            void MyListView::dropEvent(QDropEvent * event)
            {
              if (event->source() != this || indexAt(event->pos()).isValid())
              {
                QListView::dropEvent(event);
              }
            }
            
            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved