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. QStyledItemDelegate - implement drag event?

QStyledItemDelegate - implement drag event?

Scheduled Pinned Locked Moved Solved General and Desktop
qstyleditemdeleqdragqdrag drag dropqtreeview
2 Posts 1 Posters 653 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 27 Sept 2019, 03:38 last edited by Dariusz
    #1

    Hey

    So I've implemented my widget look in QStyledItemDelegate, it has few buttons and lineEdits as "widgets" all hand drawn at the moment.

    I would like now to allow for some "dragging" so user can drag on to the "widgets". As far as I can tell there will be 2 drag modes, 1 dragging treeItem itself, 2 dragging widget on to treeItem - custom Widget I draw to perform some action.

    I've implemented this in my EditorEvent() function to determine drag start/action, but the second I drag the item "outside" the "treeItem" the treeItem drag operation kick in and my initialized drag appear to be lost... I'm fairly sure I'm doing this in wrong place... any help would be great... some code :

            if self.leftPressed:
                if self.handleDrag(event, option, index) and self.mDragBegin == False:
                    self.mDragBegin = True
                    return True
    
                if self.mDragBegin and self.dragInitialized == False:
                    mMouseDragDistance = (event.pos() - self.mMousePressPos).manhattanLength();
                    print("Drag Distance : ", mMouseDragDistance)
                    if mMouseDragDistance > 4:
                        self.initializeDrag(event, option, index)
                    return True
                if self.dragInitialized:
                    print("its dragging now!")
                    return True
    
                print("we go back to native impl")
                return super().editorEvent(event, model, option, index)
    
        def initializeDrag(self, event, option, index):
            self.dragInitialized = True
            print("Drag initialized!")
            drag = QDrag(self)
            state = drag.exec_()
            print("Drag state : ", state)
    
    

    TIA

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on 27 Sept 2019, 20:05 last edited by
      #2

      Yo

      It appears that I was almost there... just need to create a proper drag!

      def initializeDrag(self, event, option, index):
              self.dragInitialized = True
              print("Drag initialized!")
              drag = QDrag(self)
              mim = QMimeData()
              mim.setText("yoyoyooy")
              drag.setMimeData(mim)
              val = drag.exec_()
              print("Return drag val : ", val)
              self.dragInitialized = False
      

      Once thats made, I then have to handle dragEnterEvent on QTreeView and then pass it to proper function from there... yay!

      1 Reply Last reply
      0

      1/2

      27 Sept 2019, 03:38

      • Login

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