[Interest] Getting QTreeView item click offset for DnD

Jason H scorp1us at yahoo.com
Tue Apr 17 18:25:29 CEST 2012


To elaborate, the mouse press event is being reimplemented so I can record where the user clicked, since none of the data contains the mouse coord relative to the delegate. 

Imagine a delegate 50x100. I click in the exact center (25,50) the drop event supplies the mouse coordinate (x,y). To drop this where it should go, I need to place it at (x-25, y-50). However nothing I see would ever tell me (25,50) is where the mouse is.





________________________________
 From: Jason H <scorp1us at yahoo.com>
To: André Somers <andre at familiesomers.nl>; "interest at qt-project.org" <interest at qt-project.org> 
Sent: Tuesday, April 17, 2012 11:09 AM
Subject: Re: [Interest] Getting QTreeView item click offset for DnD
 

Yes. However nothing gives me the click coordinates.

I am dragging an item to a subclassed QLabel. When the drop occurs, the top-left of the item is placed at the mouse cursor. This is wrong. The item should be placed at wherever Qt drew it last, which is offset by the mouse coords in the item. 




________________________________
 From: André Somers <andre at familiesomers.nl>
To: "interest at qt-project.org" <interest at qt-project.org> 
Sent: Tuesday, April 17, 2012 11:00 AM
Subject: Re: [Interest] Getting QTreeView item click offset for DnD
 

Op 17-4-2012 16:54, Jason H schreef: 
Well I am confused about how the view works.
>I'm using QStandardItems, so whatever Qt does with those... I can't find documentation anywhere...
>
>
The items in the model do not become widgets. That would be very inefficient. Instead, they are rendered in the view using a delegate that has been set on your view. By default, that is a QStyledItemDelegate. 

Anyway, for D&D purposes, an item is just a package of data. At
    the moment you have the model index, you have access to the data of
    the item. 

Perhaps the question should be: why are you reimplementing the
    mousePressEvent in this context at all? Did you study the "Using
    Drag and Drop with Item Views" topic from the Model/View Programming
    documentation page?

André




>
>
>________________________________
> From: André Somers <andre at familiesomers.nl>
>To: interest at qt-project.org 
>Sent: Tuesday, April 17, 2012 10:40 AM
>Subject: Re: [Interest] Getting QTreeView item click offset for DnD
> 
>
>Op 17-4-2012 16:35, Jason H schreef: 
>I need to repeat this. I'm still lost.
>>here is my code (child is always NULL):
>>
>>voidDataPointTreeView::mousePressEvent(QMouseEvent*event) 
>>{
>>QTreeView::mousePressEvent(event);
>>QModelIndexmi=indexAt(event->pos());
>>QWidget*child=indexWidget(mi);
>>//QWidget*child=static_cast<QWidget*>(childAt(event->pos()));
>>if(!child)
>>return;
>>m_dragOffset=event->pos()-child->pos();
>>}
>>
>>
Are you even using widgets for your items? I mean: do you call setIndexWidget anywhere? If not, perhaps you should check what indexWidget() actually returns?
>

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120417/743d2271/attachment.html>


More information about the Interest mailing list