I am trying to make a QStyledItemDelegate behave like a custom QWidget I wrote, so I can switch my code to a model/view approach.
The custom QWidget is a complex button which shows four "sub buttons" in it's corners on mouse over (so all in all there are five signals). It's also drag&droppable with a custom drag pixmap. To achieve this I am using mousePressEvent, mouseReleaseEvent, mouseMoveEvent, enterEvent and leaveEvent. This is what it looks like with and without the "sub buttons" shown on mouse over:
I have since switched my main code to use a model/view approach and am trying to use this widget as a QStyledItemDelegate for my customised ListView. I have tried assigning the custom Widget as an editor like this:
class ToolButtonDelegate( QStyledItemDelegate ):
def __init__( self, parent=None ):
super( ToolButtonDelegate, self).__init__( parent )
self.parent = parent
def createEditor( self, parent, option, index ):
if not index.isValid():
return False
btn = FancyButton( index.data( Qt.UserRole ), parent=parent )
return btn
This seems promising as it draws the "FancyButton" class for the item I click on. However, I need this to be a mouse over event. After a bit more research I tried connecting the QAbstractItemView.entered slot to QAbstractItemView.edit signal:
self.entered.connect( self.edit )
This works only for the first item I move my mouse pointer over, then I get these errors:
edit: editing failed
So now I'm stuck again with these problems:
- how to properly close the editor (there is no "QAbstractItemView.leave" event or similar).
- how to ensure that the mouse clicks actually trigger the buttons in the FanyButton class rather than just interact with the QAbstractIremView
I have a feeling I'm heading into the wrong direction here.