[PyKDE] Re: pyuic and Access to QGridLayout

Chad Brantly cbrantly at darwin.sfbr.org
Wed Feb 8 14:59:55 GMT 2006


Phil Thompson wrote:
> On Wednesday 08 February 2006 4:57 am, Chad Brantly wrote:
> 
>>Chad Brantly wrote:
>>
>>>Phil Thompson wrote:
>>>
>>>>Mailing list is fine - but send the ui file you are using. Also, first
>>>>check that pyuic behaves differently to uic - otherwise it's not a bug
>>>>and won't get changed.
>>>
>>>Hi Phil,
>>>
>>>Thanks for responding.  I don't know anything about C or uic, so I can't
>>>really tell you if uic behaves differently.  I will have to take the
>>>word of Andreas on that one.
>>>
>>>I made a simplified .ui file that illustrates the problem I am
>>>discussing and the corresponding .py file created with pyuic.  In the
>>>.ui file I named the layout grid in question 'inner_grid', but this name
>>>is not preserved in the .py file.  From what I can tell, this behavior
>>>mimics uic.  However, in the attached form1.py file, shouldn't
>>>'group_boxLayout' be 'self.group_boxLayout'?  If it was I would be able
>>>to add or change items in the grid later on in my python code.
>>>
>>>I apologize for my ignorance of C.  I guess that it speaks to the power
>>>and simplicity of python that someone like me with no programming
>>>background can do the things I am able to do with it.  PyQt and pyuic
>>>make a great package.  Thank you for all of the work you have done on
>>>this project, and thank you for your help with this issue.
>>>
>>>-Chad
>>>
>>>------------------------------------------------------------------------
>>>
>>>Form1 Form1 0 0 400 224 Form1 main_grid group_box group_box inner_grid
>>>textEdit2 textEdit1
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>># -*- coding: utf-8 -*-
>>>
>>># Form implementation generated from reading ui file 'form1.ui'
>>>#
>>># Created: Sat Feb 4 00:22:45 2006
>>>#      by: The PyQt User Interface Compiler (pyuic) 3.14.1
>>>#
>>># WARNING! All changes made in this file will be lost!
>>>
>>>
>>>import sys
>>>from qt import *
>>>
>>>
>>>class Form1(QMainWindow):
>>>    def __init__(self,parent = None,name = None,fl = 0):
>>>        QMainWindow.__init__(self,parent,name,fl)
>>>        self.statusBar()
>>>
>>>        if not name:
>>>            self.setName("Form1")
>>>
>>>
>>>        self.setCentralWidget(QWidget(self,"qt_central_widget"))
>>>        Form1Layout =
>>>QGridLayout(self.centralWidget(),1,1,11,6,"Form1Layout")
>>>
>>>        self.group_box = QGroupBox(self.centralWidget(),"group_box")
>>>        self.group_box.setColumnLayout(0,Qt.Vertical)
>>>        self.group_box.layout().setSpacing(6)
>>>        self.group_box.layout().setMargin(11)
>>>        group_boxLayout = QGridLayout(self.group_box.layout())
>>>        group_boxLayout.setAlignment(Qt.AlignTop)
>>>
>>>        self.textEdit2 = QTextEdit(self.group_box,"textEdit2")
>>>
>>>        group_boxLayout.addWidget(self.textEdit2,0,1)
>>>
>>>        self.textEdit1 = QTextEdit(self.group_box,"textEdit1")
>>>
>>>        group_boxLayout.addWidget(self.textEdit1,0,0)
>>>
>>>        Form1Layout.addWidget(self.group_box,0,0)
>>>
>>>
>>>
>>>        self.languageChange()
>>>
>>>        self.resize(QSize(400,224).expandedTo(self.minimumSizeHint()))
>>>        self.clearWState(Qt.WState_Polished)
>>>
>>>
>>>    def languageChange(self):
>>>        self.setCaption(self.__tr("Form1"))
>>>        self.group_box.setTitle(self.__tr("group_box"))
>>>
>>>
>>>    def __tr(self,s,c = None):
>>>        return qApp.translate("Form1",s,c)
>>>
>>>if __name__ == "__main__":
>>>    a = QApplication(sys.argv)
>>>    QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
>>>    w = Form1()
>>>    a.setMainWidget(w)
>>>    w.show()
>>>    a.exec_loop()
>>
>>Phil,
>>
>>Can you tell me if this is the intended behavior or not?  I have a
>>workaround for now, but I just wanted to check for future reference.
> 
> 
> It is intended behaviour. pyuic has never directly exposed the layouts. PyQt 
> v3.15 improved the conversion code so that the correct layout class was 
> returned when you walked the tree of objects, so that method should be 
> reliable.
> 
> Phil
> 
So should I access it with self.group_box.layout().layout() or something 
like that?  Right now I am using self.group_box.layout().children()[0] 
but this would only work in the case of one child, right?

-Chad




More information about the PyQt mailing list