i want to hide the "dragging indicator"(the dragged row screenshot) only show mouse arrow when dragging in QTreeWidget
, is it possible?
i tried to reimplement mouseMoveEvent
, the "dragging indicator" went away but at the same time , drag/drop is disabled, what am i missing
code:
#!/usr/bin/env python2
import os
import sys
import re
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt, QString
class MyTreeWidget(QtGui.QTreeWidget):
def mouseMoveEvent_xxx(self, e):
mimeData = QtCore.QMimeData()
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
# pixmap = QtGui.QPixmap()
# drag.setPixmap(pixmap)
# drag.setHotSpot(e.pos())
# QtGui.QTreeWidget.mouseMoveEvent(self,e)
drag.exec_(QtCore.Qt.MoveAction)
def dropEvent(self,e):
QtGui.QTreeWidget.dropEvent(self,e)
self.expandAll()
e.accept()
class TheUI(QtGui.QDialog):
def __init__(self, args=None, parent=None):
super(TheUI, self).__init__(parent)
self.layout = QtGui.QVBoxLayout(self)
treeWidget = MyTreeWidget()
button = QtGui.QPushButton('Add')
self.layout.addWidget(treeWidget)
self.layout.addWidget(button)
treeWidget.setHeaderHidden(True)
self.treeWidget = treeWidget
self.button = button
self.button.clicked.connect(lambda *x: self.addCmd())
HEADERS = ( "script", "chunksize", "mem" )
self.treeWidget.setHeaderLabels(HEADERS)
self.treeWidget.setColumnCount( len(HEADERS) )
self.treeWidget.setColumnWidth(0,160)
self.treeWidget.header().show()
self.treeWidget.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.resize(500,500)
for i in xrange(6):
item =self.addCmd(i)
if i in (3,4):
self.addCmd('%s-1' % i,parent=item)
self.treeWidget.expandAll()
self.setStyleSheet("QTreeWidget::item{ height: 30px; }")
def addCmd(self, i,parent=None):
'add a level to tree widget'
root = self.treeWidget.invisibleRootItem()
if not parent:
parent=root
item = QtGui.QTreeWidgetItem(parent,['script %s' %i,'1','150'])
return item
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = TheUI()
gui.show()
app.exec_()
screenshot:
i want to hide the blue dragged bar, while keeping the mouse arrow.( or give it some custom pixmap, or better draw an dotted outline around the dragged bar), the idea being not want to obscure the tree content behind it, ( in my system comopositing manager is disabled, so semi transparency is impossible )
if you rename mouseMoveEvent_xxx to mouseMoveEvent, you will see what i meant, dragging is disabled, although i've set dragDropMode to InternalMove