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

Frank Rueter | OHUfx frank at ohufx.com
Fri Jun 29 08:58:38 CEST 2012

Hi all,

I am trying to build an animated version of the QStackedLayout where the 
requested widget pushes the previous one out of frame.
I got it all working so far but the one thing I don't know how to do is 
to restrict the widgets's visibility to the layout's geometry, so that 
when they animate away, they get cropped and disappear from view, rather 
than just being drawn on top of everything else around the parent layout.

Below is a very simple example of what I'm trying to "fix". The button 
is manually moved but somehow I need it to not be visible where it's 
outside the layout.

Any ideas?


The actual code is here:

import sys
from PySide.QtGui import *
from PySide.QtCore import *

app = QApplication( sys.argv )

mainWidget = QWidget()
frame = QFrame()
frame.setFrameStyle( QFrame.Box )
label = QPushButton( 'this should only be visible inside the layout geo' )
label.setParent( mainWidget )

label.resize( 500, 50 )

layout = QVBoxLayout()
mainWidget.setLayout( layout )

layout.addWidget( frame )

mainWidget.resize( 500, 200 )
sys.exit( app.exec_() )

More information about the PySide mailing list