Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Drag&Dropping last index item of a QListWidget removes its contents
Forum Updated to NodeBB v4.3 + New Features

Drag&Dropping last index item of a QListWidget removes its contents

Scheduled Pinned Locked Moved Solved Qt for Python
pyside2
3 Posts 2 Posters 452 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.
  • A Offline
    A Offline
    alexmaje
    wrote on last edited by alexmaje
    #1

    Hello, this is my setup:

    # essential bits
    class DropOffArea(QListWidget):
        def __init__(self):
            super().__init__()
            self.setSelectionMode(QListWidget.ExtendedSelection)
            self.setLayoutMode(QListWidget.SinglePass)
            self.setFlow(QListWidget.LeftToRight)
            self.setDragDropMode(QListWidget.InternalMove)
    
            # QWidget subclass, contains buttons and sliders
            item1 = LightPanelWidget(hou.node('/obj/rslight1'), parent=self) 
    
            list_item1 = QListWidgetItem()
            list_item1.setSizeHint(QSize(90, 100))
            self.addItem(list_item1)
            self.setItemWidget(list_item1, item1)
    

    The default dragdrop mode works like an absolute charm except when I drag&drop the last item beyond itself, then it loses the widgets. Works fine if the dragged item isn't last.

    problem.gif

    Is this expected and what can I try to resolve this?

    JonBJ 1 Reply Last reply
    0
    • A alexmaje

      Hello, this is my setup:

      # essential bits
      class DropOffArea(QListWidget):
          def __init__(self):
              super().__init__()
              self.setSelectionMode(QListWidget.ExtendedSelection)
              self.setLayoutMode(QListWidget.SinglePass)
              self.setFlow(QListWidget.LeftToRight)
              self.setDragDropMode(QListWidget.InternalMove)
      
              # QWidget subclass, contains buttons and sliders
              item1 = LightPanelWidget(hou.node('/obj/rslight1'), parent=self) 
      
              list_item1 = QListWidgetItem()
              list_item1.setSizeHint(QSize(90, 100))
              self.addItem(list_item1)
              self.setItemWidget(list_item1, item1)
      

      The default dragdrop mode works like an absolute charm except when I drag&drop the last item beyond itself, then it loses the widgets. Works fine if the dragged item isn't last.

      problem.gif

      Is this expected and what can I try to resolve this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @alexmaje
      There are quite a few hits for this if you Google QListWidget.InternalMove. https://stackoverflow.com/questions/30291628/internalmove-in-qlistwidget-makes-item-disappear suggests

      setDefaultDropAction(Qt::TargetMoveAction);
      #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
          myList->setMovement(QListView::Free);
      #endif
      

      Does this make it not disappear for you?

      Then see also possible https://forum.qt.io/topic/143860/qlistwidget-drag-drop-item-disappear

      A 1 Reply Last reply
      2
      • JonBJ JonB

        @alexmaje
        There are quite a few hits for this if you Google QListWidget.InternalMove. https://stackoverflow.com/questions/30291628/internalmove-in-qlistwidget-makes-item-disappear suggests

        setDefaultDropAction(Qt::TargetMoveAction);
        #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
            myList->setMovement(QListView::Free);
        #endif
        

        Does this make it not disappear for you?

        Then see also possible https://forum.qt.io/topic/143860/qlistwidget-drag-drop-item-disappear

        A Offline
        A Offline
        alexmaje
        wrote on last edited by
        #3

        @JonB I wasn't even aware my widgets would disappear when dragging it in the middle like that -- but they did as well!

        The second link seems to have solved it. Thank you so much for help!

        Just in case anyone finds this in the future, here's the Python version:

        def dragMoveEvent(self, e):
                if (
                    (self.row(self.itemAt(e.pos())) == self.currentRow() + 1)
                    or (self.currentRow() == self.count() - 1 and self.row(self.itemAt(e.pos())) == -1)
                ):
                    e.ignore()
                else:
                    super().dragMoveEvent(e)
        
        1 Reply Last reply
        2
        • A alexmaje has marked this topic as solved on

        • Login

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