From pykde Fri May 20 22:13:55 2005 From: John Ridley Date: Fri, 20 May 2005 22:13:55 +0000 To: pykde Subject: Re: [PyKDE] autoAdding buttons to a grid Message-Id: <20050520221355.97283.qmail () web26807 ! mail ! ukl ! yahoo ! com> X-MARC-Message: https://marc.info/?l=pykde&m=111662735207559 --- Richard Smith wrote: > I must be finally starting to catch on. I worked out how to make the > QbuttonGroup operate pretty close to what I want. > > The code I ended up with is below. > > One thing I this still dosen't do is resize all the buttons when the > number of columns is changed. I want the button widths to shrink > with > repect to how wide I set the > QButtonGroup to be. > > QGridLayout seems to be what I want to use to do all this for me but > I > haven't yet fully grokked how to make that happen. Is this anything like what you had in mind? >>> import sys >>> from qt import * >>> class Form(QDialog): ... def __init__(self): ... QDialog.__init__(self) ... self.grid = QGridLayout(None,1,1,0,6) ... p = QSizePolicy.Expanding; p = QSizePolicy(p,p,0,0,1) ... b = QPushButton('Add Row',self); b.setSizePolicy(p) ... self.connect(b,SIGNAL('clicked()'),self.addbuttons) ... self.grid.addWidget(b,0,0) ... b = QPushButton('Add Col',self); b.setSizePolicy(p) ... self.connect(b,SIGNAL('clicked()'),self.addcol) ... self.grid.addWidget(b,1,0) ... g = QGridLayout(self,1,1,10,6) ... g.addLayout(self.grid,0,0) ... self.resize(QSize(300,300)) ... def addbuttons(self, col=0): ... k = [self.grid.numRows(),self.grid.numCols()] ... if col: k.reverse() ... for n in range(k[1]): ... b = QPushButton('Button', self) ... b.setSizePolicy(QSizePolicy( ... QSizePolicy.Expanding,QSizePolicy.Expanding,0,0,1)) ... if col: self.grid.addWidget(b,n,k[0]) ... else: self.grid.addWidget(b,k[0],n) ... b.show() ... def addcol(self): ... self.addbuttons(1) ... >>> A = QApplication(sys.argv) >>> F = Form(); A.setMainWidget(F); F.show() >>> A.exec_loop(); del F,A HTH John Ridley ___________________________________________________________ Does your mail provider give you FREE antivirus protection? Get Yahoo! Mail http://uk.mail.yahoo.com _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde