[PySide] Fwd: re-implementing setDown() for custom button

Srini Kommoori vasure at gmail.com
Fri May 4 08:56:24 CEST 2012


Forgot to cc the list. May be useful for archival purposes.

---------- Forwarded message ----------
From: Srini Kommoori <vasure at gmail.com>
Date: Thu, May 3, 2012 at 11:50 PM
Subject: Re: [PySide] re-implementing setDown() for custom button
To: Frank Rueter | OHUfx <frank at ohufx.com>


Frank,

Here is a simple working example.

https://gist.github.com/2592661

I tried to debug your snippet but it was taking too long to see what is
happening with the new button in your example.

May be check with the working example that I have posted and compare with
what you are doing in the new button.

Hope that helps.

-Srini


On Thu, May 3, 2012 at 2:21 PM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:

>  Thanks. I'm just trying to see what I could do better, as I'm very new to
> QT.
> So you reckon it would just be better to use the dragMoveEvent virtual
> function instead of the dragEnterEvent?
>
> I can't see a difference between the two in my code even though they
> should make the button itself receive drag events, right?! So I guess I
> should see the plus icon after all like I do with the defaul tbutton, but I
> don't.
>
> I must still be missing something obvious.
>
> Cheers,
> frank
>
>
> On 4/05/12 9:15 AM, Srini Kommoori wrote:
>
> Sorry Safari auto correction making it illegible.
>
>  What I meant was, I would prefer to have dragMoveEvent
> with event.setDropAction(QtCore.Qt.CopyAction).
>
>  You can ignore the comment as you have custom implemented the whole
> pushbutton and its behavior.
>
>  -Srini
>
> On Thu, May 3, 2012 at 1:32 PM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:
>
>>  Hi Srini,
>>
>>
>> >>(I would prefer to do have dragMoveEvent)
>>  I'm not quite sure what you mean. Can you elaborate?
>>
>> I did what you suggested but can't see any change (maybe because I'm on
>> osx?).
>>
>> Cheers,
>> frank
>>
>>
>> On 3/05/12 9:49 PM, Srini Kommoori wrote:
>>
>> Thats great.
>>
>>  One thing I observed is: for your custom button, if you want a
>> nice/native copy icon to appear - set following in your dragEnterEvent(I
>> would prefer to do have dragMoveEvent)
>>
>>  event.setDropAction(QtCore.Qt.CopyAction)
>> event.accept()
>>
>>  -Srini
>>
>> On Thu, May 3, 2012 at 1:51 AM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:
>>
>>>  DOH. Minutes after posting this I realised that the little plus on the
>>> cursor only shows up on a "droppable" area, which my custom button is not
>>> (and the default one is I guess).
>>> In other words I just solved all the problem myself by trying to strip
>>> it all down for a test to post.
>>> Sorry, will try and be a bit more accountable next time.
>>>
>>>
>>>
>>>
>>> On 3/05/12 8:37 PM, Frank Rueter | OHUfx wrote:
>>>
>>> Here is some example code that I ripped out of my main code:
>>> http://pastebin.com/jXZXXebW
>>>
>>> It compares a sub classed QPushButton with one I painted from scratch.
>>>
>>> I was actually able to solve some of the problems in the process (and
>>> for some reason the QObject.sender() works as well now) , but the one thing
>>> that still doesn't work with the new button is when I try to set a drag
>>> action like this:
>>> drag.start( Qt.CopyAction )
>>>
>>> The drag action for the "new button" is in line 192 which doesn't seem
>>> to have any effect when dragging the button, while the one for the "old
>>> button" in line 27 works as expected and turns the mouse cursor into a
>>> little plus sign when dragging.
>>>
>>> What am I missing?
>>>
>>>
>>> Cheers,
>>> frank
>>>
>>>
>>> On 3/05/12 7:11 PM, Frank Rueter | OHUfx wrote:
>>>
>>> Indeed, my apologies.
>>> Will strip out the relevant parts and post an example soon.
>>>
>>> On 3/05/12 7:06 PM, Srini Kommoori wrote:
>>>
>>> Code snippet would help in understanding what you are asking.
>>>
>>>  For most of my cases this works great:
>>>        pushButton.clicked.connect(findFile)
>>>
>>>  If you are trying to implement your own style button, QPushButton also
>>> takes icon.
>>>
>>>
>>>  On Wed, May 2, 2012 at 11:23 PM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:
>>>
>>>> Any takers?
>>>> I'm kinda stuck with this one unfortunately.
>>>>
>>>>
>>>> On 2/05/12 6:35 PM, Frank Rueter | OHUfx wrote:
>>>> > sorry for the monolog, but I just realised I will also have to make my
>>>> > custom button play along when it's parent's self.sender() function is
>>>> > called as well.
>>>> > The QSignalSender doesn't quite seem to be the right thing to use as
>>>> it
>>>> > is implemented in the parent's constructor, however I would like to
>>>> > implement this in the button's class if possible to make it self
>>>> contained.
>>>> >
>>>> > How would I go about that?
>>>> >
>>>> > Cheers,
>>>> > frank
>>>> >
>>>> > On 2/05/12 5:44 PM, Frank Rueter | OHUfx wrote:
>>>> >> Hi,
>>>> >>
>>>> >> to follow up my previous mail, I also just noticed that I have to
>>>> >> re-implement the QAbstractButton's setDown() function to make sure my
>>>> >> custom button doesn't stay down after a drag&drop action.
>>>> >>
>>>> >> With a QPushButton I simply called self.setDown( False ) from inside
>>>> the
>>>> >> mouseMoveEvent, so now I'm trying to understand how to recreate this
>>>> >> behaviour when using a custom paintEvent().
>>>> >>
>>>> >> Any tips would be greatly appreciated.
>>>> >>
>>>> >> Cheers,
>>>> >> frank
>>>> >> _______________________________________________
>>>> >> 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
>>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> PySide mailing listPySide at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/pyside
>>>
>>>
>>>
>>> _______________________________________________
>>> PySide mailing listPySide at qt-project.orghttp://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/20120503/28cbb57c/attachment.html>


More information about the PySide mailing list