[PySide] uncheck button after drag&drop

Frank Rueter | OHUfx frank at ohufx.com
Mon Apr 16 03:13:57 CEST 2012


Hi all,

in case somebody is interested:
I've managed to implement "sloppy clicks", i.e. clicks during which the 
mouse pointer moves a little bit (happens a lot when using a wacom pen). 
This was a problem because the buttons need to be "dragable", and the 
moment the mouseMoveEvent started, the mouseReleaseEvent never got 
called. So even a 1 pixel shift which feels like a click to the user 
wouldn't result in the expected behaviour.

http://pastebin.com/XK3QguAH

I'm not sure if this is the best solution though, as I basically had to 
enable and implement drop events for the button itself, then compare the 
position where the button was dropped vs. it's original position. If the 
distance is within a given threshold (in my case 5 pixels) then the same 
function is called as is used by the mouseReleaseEvent().

Using the above and the mouseReleaseEvent rather than the 
mousePressEvent enables me to make the buttons "dragable" with the same 
mouse button as they are clicked with, and be able to differentiate 
between dragging event and a "sloppy" click.

I don't feel this is the right way to go about it though, so any 
suggestions on how to do this more elegantly would be appreciated.

Cheers,
frank



On 4/14/12 3:40 PM, Frank Rueter | OHUfx wrote:
> Sweet, the setDown() method was what I needed, thanks!
> It's a little disapointing that the right and middle mouse click 
> events don't seem to work on a mac though.
>
> I guess in that case I will have to make sure that the mousePressEvent 
> isn't called when the button is dragged. Is there an elegant way to 
> set some sort of threshold or check if the button was moved a certain 
> distance between the mouseDown and mouseUp events, and if so, don't 
> trigger the mousePressEvent? Will have a play, I might have just 
> answered my own question :-D
>
> Cheers,
> frank
>
> On 14/04/12 2:01 AM, Aaron Richiger wrote:
>> Hello Frank and Sebastian!
>>
>> You are both right... Because you are discussing about different 
>> code, I guess. The tutorial indicated by Frank does not work on Mac 
>> for me (maybe, I am just to stupid to figure out how to trigger a 
>> RightMouseButtonEvent on Mac, but anyways), so I guess, Sebastian 
>> tried the code of the tutorial on Windows, where right clicks 
>> perfectly work, but they do not leave down the original button.
>> Then I guess, Frank changed the tutorial code slightly to drag and 
>> drop with left clicks on MacOS. And there it is, the original button 
>> stays down after dragging and I think, this behaviour is platform 
>> independent, so Sebastian would get the same problem I guess...
>> But it's not a bug of PySide or Qt, but just the normal behaviour of 
>> buttons, if you click them with the left mousebutton. They are 
>> looking "down", to repair this, simply call self.setDown(False) in 
>> the mouseMoveEvent() method. You get a changed version of the 
>> tutorial (not only dragNdrop, but also creating a new widget as Frank 
>> wanted) here:
>>
>> http://pastebin.com/GMbcCWYM
>>
>> Play around dragging the buttons with the left mouse button and 
>> uncomment the self.setDown() call to see Franks issue platform 
>> independent.
>>
>> Lot's of "guesses" and "maybes", but could be the solution...
>> Aaron
>>
>>
>>
>>> I guess this is a bug in PySide, which may depend on OS. I do not 
>>> have this behaviour on win xp with newest Pyside and python 26
>>>
>>>
>>>
>>>
>>>  On 04/13/2012 10:54 AM, Frank Rueter | OHUfx wrote:
>>>> Hi everyone,
>>>>
>>>> me again :)
>>>>
>>>> I just implemented the tutorial on this page 
>>>> <http://zetcode.com/gui/pysidetutorial/dragdrop/> into my code as I 
>>>> needed to be able to copy QPushButtons from one widget to another 
>>>> via Drag&Drop. It all works great, accept for the fact that the 
>>>> original button that I drag becomes checked and stays checked after 
>>>> I drop it into the other widget.
>>>> The example on the above page actually has the same problem accept 
>>>> it doesn't matter in that example.
>>>>
>>>> The QPushButton is not set to be checkable and I've tried using 
>>>> setChecked( False ) on the button both in the dragEnterEvent as 
>>>> well as the dropEvent, but to no avail.
>>>>
>>>> Any ideas how to make the button uncheck itself after it was dropped?
>>>>
>>>>
>>>> Cheers,
>>>> frank
>>>>
>>>>
>>>> _______________________________________________
>>>> PySide mailing list
>>>> PySide at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>
>>>
>>> -- 
>>> Sebastian Elsner    -    pipeline td   -   r i s e |  fx
>>>
>>> t:  +49 30 20180300sebastian at risefx.com
>>>                                            www.risefx.com
>>>
>>> r i s e |  fx  GmbH
>>> Schlesische Strasse 28 Aufgang B, 10997 Berlin
>>> Geschäftsführer: Sven Pannicke, Robert Pinnow
>>>
>>> Handelsregister Berlin HRB 106667 B
>>>
>>>
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120416/41a84901/attachment.html>


More information about the PySide mailing list