PDA

View Full Version : Problem with auto expand on treeview



piquadrat
25th April 2009, 08:53
Hi,

I have a custom treemodel and a treeview, with a QSortFilterProxyModel in between (all in PyQt4). It looks like this:
http://undercover.piquadrat.ch/raw-attachment/wiki/_attachments/screenshot_linux.png

Now, I want to drag images from the listview (the widget in the middle) to the treeview, but only on second level items (the ones with the colored circles in front of them). I want to use setAutoExpandDelay, so that top level items get expanded when a drag hovers over them. I've got a couple of problems, though:


If I hover over a second level element, Qt apparently tries to expand it, although it has no children. The outline around the hovered item vanishes, and the following error messages are printed:

QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setWorldTransform: Painter not active
QPainter::end: Painter not active, aborted

My model correctly returns a rowCount of zero, so I have no idea why Qt wants to expand them.
When I hover over a top level item, Qt expands it as expected. But when I hover over a second top level item during the same drag operation, it doesn't get expanded.


I checked my model with ModelTest (http://labs.trolltech.com/page/Projects/Itemview/Modeltest), it doesn't detect any errors in my model.

Here's my treeview (http://undercover.piquadrat.ch/browser/src/undercover/gui/widgets.py#L124), and my tree model (http://undercover.piquadrat.ch/browser/src/undercover/gui/models.py#L28)

piquadrat
26th April 2009, 11:21
I worked around my first problem by enabling and disabling autoexpand, depending on the item that is below the mouse during a drag action:


def dragMoveEvent(self, event):
item = self.model().proxy_item(self.indexAt(event.pos()))
if hasattr(item, 'query'):
# second level
self.setAutoExpandDelay(-1)
else:
# top level
self.setAutoExpandDelay(500)
QtGui.QTreeView.dragMoveEvent(self, event)

But that's just gross. And it doesn't solve my second problem. Any other ideas?