Hello Frank!

I still think, that delegates are not the best option here... I played around with the current version of your project and noticed the following:

- Using IconMode for the QListview is not thought for your use of making a QListView with two columns. IconMode is used if there is a relation between the first item (icon) and the second item(e.g. label). A typical example is a FileBrowser, where you have the icon first and the filename after. Since you have absolutely no connection between your first and second item, this is the wrong choice. It would be better to use QTableView in such a case (with the advantage, that you can easily change your GUI later to display three or four columns instead of just two, which would not be possible with your solution) - I still think, that delegates are not the best option for your purpose. Usually, delegates are for editing the data of the underlying model, but in your case, you don't want to change the data of the model, but start an action (e.g. on mouseClick). I think, it would be easier to implement it without delegates!

I would implement it the following way:

- Define the grid of widgets and the widgets in the view, emit signals for your mouse operations (enter, leave, drag and drop etc.) - Handle this signals in the controller and propagate changes to the model if there are any (e.g. drag and drop changes the order)

Have a nice evening!
Aaron



Am 02.07.2012 08:18, schrieb Frank Rueter | OHUfx:
I'm half a step closer I think:

I'm using the QStyledItemDelegate.createEditor method to assign my custom widget to the delegate as an editor:


class ToolButtonDelegate( QStyledItemDelegate ):
'''Delegate for ToolView. Might have to use widget instead to get mouse over effects'''
    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 draws the "FancyButton" widget when the item is clicked, or whatever else the View's editTriggers are set to. Unfortunately there is no "mouseOver" edit trigger which could have been a feasible workaround.

I am just experimenting with connecting the QAbstractView.entered signal to the QAbstractView.edit slot but with very limited success. I get the editor on mouse over for the first item, but it stays open and I get "edit: editing failed" on all subsequent enter event. There is no "left" signal to close the editor again when the mouse cursor leaves the respective item, so I'm not sure if it's possible to use this approach.





On 2/07/12 5:20 PM, Frank Rueter | OHUfx wrote:
Does anybody have an idea how to do this?
This seems to be turning into a show stopper for me.
I found this thread but since it's C++ I have a hard time deciphering it: http://www.qtcentre.org/threads/8660-Drawing-a-widget-in-QItemDelegate-s-paint-method

I don't need to edit the item data, just need to represent it with a custom widget (showing various buttons inside the widget on mouse over) and make it drag&dropable.

I've attached a screen grab of what my working custom widget looks like (with and without mouse over). I hope it comes through ok.
I *just* need to be able to use this as a delegate somehow.


Cheers,
frank




On 25/06/12 3:47 PM, Frank Rueter | OHUfx wrote:
Hi all,


I'm just re-writing part of my existing code to use the mode/view approach.

I already have a complex custom widget which is a large button that can
be dragged and dropped, and that shows "sub buttons" on mouse over (i.e.
smaller rectangles are displayed in the corners on mouse over which act
as buttons in their own right).

The whole widget works exactly like I want it to, but now I'm wondering
if it's possible to create a QStyledItemdelegate for the new model/view
approach to do the same thing. It will need the same event handling as
my custom widget, such as enterEvent, leaveEvent, mouseReleaseEvent,
mousePressEvent, mouseReleaseEvent and mouseMoveEvent.

Is this possible with a delegate? Or can it be achieved in other ways?
Any pointers would be much appreciated.

Cheers,
frank

_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside




_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside




_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside


_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to