[PySide] restricting a widget to only be visible inside it's layout's geometry

Aaron Richiger a.richi at bluewin.ch
Mon Jul 2 01:01:58 CEST 2012


Hello frank!

Yes, exactly, the dummy widget will be your friend:-)! I noticed, that 
the QFrame is only for demonstration purposes, but this doesn't matter, 
since it works the same way with every other widget (because they all 
inherit from QWidget) and for layouts, you can just do the trick with 
using the layout in an invisible dummy widget.

Concerning the white spaces, you will of course find other python 
programmers that don't agree with me, but I'm quite sure it is a 
minority, since PEP8 is the official python style guide and written by 
our Benevolent Dictator for Life and inventor of Python himself: Guido 
von Rossum :-)

Happy coding!
Aaron



Am 02.07.2012 00:32, schrieb Frank Rueter | OHUfx:
> Hi Aaron,
>
> thanks for the info.
> This is indeed what I'm after, however, I should have clarified that the
> QFrame is only in there to visualise the problem.
> Since I'm trying to create an animated layout (instead of a widget) I
> won't have anything to parent widgets to that are added to that layout.
> Maybe I just need to include a dummy widget in my layout and parent
> added widgets to that?! I will try.
>
>   >>in python, you don't write spaces after opening and before closing
> brackets
> Interesting. When I started learning python I read a style guide to
> learn the best practice which said to use white spaces in that case, so
> I got used to that. Thanks for the heads up, I will adjust my habit.
>
>   >>I replaced your setParent()
> yup, point taken. I sometimes like using setParent for clarity but am
> happy to adapt common practice.
>
> Thanks for the tips.
>
> Cheers,
> frank
>
>
> On 30/06/12 4:14 AM, Aaron Richiger wrote:
>> Hello Frank!
>>
>> This time, I'm not quite sure, whether I understood your task
>> correctly... If I got it right, you want the button to be visible only
>> within the frame box!? A widget is only visible within it's parents
>> geometry, so you can use this behaviour. In your short example, the
>> layouts and buttons parent is the mainWidget an have therefore the same
>> geometry as the mainWidget. I changed the code slightly, you will find
>> it below. Please tell me, if this is not, what you were after!
>> Additionally, note the following:
>>
>> - (Knowing, that this may be the beginning of a holy war :-)): in
>> python, you don't write spaces after opening and before closing brackets
>> (see PEP8 or the Google Python Style Guide).
>> - I replaced your setParent() calls by using the constructors parameter.
>> This makes the code shorter and is to prefer in my opinion, most
>> PySiders do it this way, but again, this is just a question of personal
>> taste... :-)
>>
>> Cheers
>> Aaron
>>
>> ########## Code ###########
>>
>> import sys
>> from PySide.QtGui import *
>> from PySide.QtCore import *
>>
>> app = QApplication( sys.argv )
>>
>> mainWidget = QWidget()
>> frame = QFrame(mainWidget)
>> frame.setFrameStyle( QFrame.Box )
>> label = QPushButton( 'this should only be visible inside the layout
>> geo', frame )
>> label.resize( 500, 50 )
>>
>> layout = QVBoxLayout( mainWidget )
>> layout.addWidget( frame )
>>
>> mainWidget.resize( 500, 200 )
>> mainWidget.show()
>> sys.exit( app.exec_() )
>> _______________________________________________
>> 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





More information about the PySide mailing list