[PySide] use text as a button / hyperlink?

Ludo Visser ludo.visser at gmail.com
Fri Apr 13 09:29:47 CEST 2012


On Apr 13, 2012, at 3:27 am, Frank Rueter | OHUfx wrote:

> I think I found a way but am not quite sure if its' the best way. I 
> subclassed QLabel and (re)implemented the mousePressEvent.
> While this seems to work I'm not quite sure how to properly use the 
> event argument required in the mousePressEvent. I just assigned a dummy 
> method for now while I'm trying to find the answer to this.
> Could someone help clarify please?
> 
> class SortWidget( QLabel ):
> 
>     def __init__( self, parent=None ):
>         super( SortWidget, self).__init__( parent )
> 
>     def myEvent( self ):
>         pass
> 
>     def mousePressEvent( self, event ):
>         print 'I was clicked'
> 
> 
> 
> On 4/13/12 12:48 PM, Frank Rueter | OHUfx wrote:
>> Hi everyone,
>> 
>> anther noob question:
>> 
>> I'm wondering what the most elegant way is to use a list of QLabels like
>> a group of QRadioButtons.
>> I am after creating a simple list of labels that will drive how a widget
>> in my UI will be sorted ('date', 'name', 'author', etc).
>> 
>> I need to do this cause I don't have enough space to use radio buttons
>> which is pretty much the functionality I need.
>> So I thought if I just have clickable labels and make the click drive
>> the sorting action that should work best in my case.
>> 
>> How would people approach this?
>> 
>> Thanks in advance,
>> frank
>> 

Hi,

The only thing your probably need to do is accept the event (http://qt-project.org/doc/qt-4.8/qevent.html#accept):

event.accept()

Sometimes, if your program is in a state where you don't want to allow sorting, you can ignore the event and/or pass it to the widget's parent.

- Ludo




More information about the PySide mailing list