[PyKDE] autoAdding buttons to a grid

Richard Smith smithbone at gmail.com
Tue May 17 14:55:34 BST 2005


I just started using pyQt and I seem to need a little guidance...

I'm trying to auto add several more QPushButtons to a QGridLayout but
I either get runtime type errors or if it dosen't error then they
don't seem to show.

I have a form with a QButtonGroup on it that I created with the
designer called bgMain.  I've subclassed my window from the class
generated by pyuic

Via the designer I have 3 buttons in the buttongroup and they are
managed by a GridLayout

So I have self.bgMain which is the reference to the buttongroup.

When one of the buttons is clicked I want to populate several more
buttons into that gridlayout in the buttongroup. I don't really care
about the order so AutoAdd seemed to be what I needed.

Looking at the pyuic code and reading the Qt docs I've come up with 

        items = ["test1","test2","test3"]
        bgMainLayout = QGridLayout(self.bgMain.layout())
        bgMainLayout.setAutoAdd(1)
        
        for each in items:
            self.bgMain.insert(QPushButton(self.bgMain,each))

        bgMainLayout.activate()

But the items never showup in my buttongroup.  

I've tried various permutations with bgMainLayout.addWidget() and
setting the row and col directly like I see done in the pyuic code but
still the items never show.

Do I have to call some refresh on the window or something?  All the QT
examples I found seems to suggest that activate() should re-layout the
grid.

Thanks.
-- 
Richard A. Smith




More information about the PyQt mailing list