[PyQt] All QGroupBoxs stretchables with a QStackWidget?

alteo_gange romanocaldoni at free.fr
Tue Oct 30 16:00:52 GMT 2007


I'm sorry for the delay.

> Do you want them all to stretch as you resize the window? 
Yes, i do.

It works with your method. Thanks!


An another method is:

I have added the method...
setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
... on the first QGroupBox and the QStackedWidget, in file2.txt:

#!/usr/bin/python
# -*- coding: Utf-8 -*-

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Gui(QWidget):
	def __init__(self):
		QWidget.__init__(self)
		
		vbox=QVBoxLayout(self)
		
		group=QGroupBox("groupbox1")
		hbox=QHBoxLayout(group)
		hbox.addWidget(QLabel("label1"))
		group.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, 
QSizePolicy.Expanding))
		vbox.addWidget(group)
		
		stacked=QStackedWidget()
		stacked.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, 
QSizePolicy.Expanding))
		
		group=QGroupBox("groupbox2")
		hbox=QHBoxLayout(group)
		hbox.addWidget(QLabel("label2"))
		stacked.addWidget(group)
		
		group=QGroupBox("groupbox3")
		hbox=QHBoxLayout(group)
		hbox.addWidget(QLabel("label3"))
		stacked.addWidget(group)
		
		vbox.addWidget(stacked)
		self.setLayout(vbox)

if __name__ == "__main__":
	app = QApplication(sys.argv)
	main = Gui()
	main.show()
	sys.exit(app.exec_())

-- 
alteo_gange



More information about the PyQt mailing list