[PyKDE] autoAdding buttons to a grid

John Ridley ojokimu at yahoo.co.uk
Thu May 19 20:53:13 BST 2005


--- Richard Smith <smithbone at gmail.com> wrote:
> Ahhh.. Ok I see.  Yeah thats a much better way.  I just had my head
> around it wrong.
> I don't know that I'm going to be able to fully determine _all_ the
> various permutations possible and have that number of groupboxes
> handy
> but I should be able to figure out most of them.  I still think I'll
> have to re-create one or two since you can't shrink a grid once
> created but we will see.

Here's a crude example that may do something like what you were
originally trying to do:

.import sys
.from qt import *
.
.class Form(QDialog):
.   def __init__(self):
.      QDialog.__init__(self)
.      self.grid = QGrid(2,self)
.      self.grid.setSpacing(3)
.      b = QPushButton("Add Button",self.grid)
.      self.connect(b,SIGNAL('clicked()'),self.handler)    
.      for n in range(1,6):
.         QPushButton("Button %d" % n, self.grid)
.      self.grid.setGeometry(QRect(10,10,200,3*b.height()))
.      self.resize(QSize(220,500))
.      self.count = 5
.   def handler(self):
.      self.count += 1
.      b = QPushButton("Button %d" % self.count,self.grid)
.      b.show(); self.grid.resize(200,self.count/2*(b.height()+3))
.
.if __name__ == "__main__":
.   A = QApplication(sys.argv)
.   F = Form(); A.setMainWidget(F); F.show()
.   A.exec_loop(); del F

> 
> I just needed knowledgeable person like yourself to enlighten me 
>

Probably a very rash assessment, but thanks anyway ;-)

Best Wishes


John Ridley


		
___________________________________________________________ 
Does your mail provider give you FREE antivirus protection? 
Get Yahoo! Mail http://uk.mail.yahoo.com




More information about the PyQt mailing list