[PyKDE] Disappearing Layout Widget

Chad Brantly cbrantly at darwin.sfbr.org
Tue Aug 9 23:07:20 BST 2005


I used Designer to make a ui file and converted it to Python using  
pyuic...let's call the output file ui.py  My intention is to import  
ui.py into my main python program so that I can make updates to the  
UI using Designer in the future without losing any of my working code.

Every thing works as expected except for layouts.  I import ui.py and  
then call it's init.  My window appears with all of the widgets I set  
up in Designer.  The problem comes when I need to add a widget to a  
QGridLayout that was instantiated by ui.__init__. All of the widgets  
instantiated in the ui.py file have 'self' prepended to their name  
except for the layouts.  As a result, there is no handle for me to  
add things to an existing layout from within my main program.

Let me give you an example.  Below is an excerpt from the ui.py file  
and from main.py.

> Excerpt from ui.py
> ===============
> ...
> class Form1(QMainWindow):
>    def __init__(self, parent=None, name=None, fl=0):
>       QMainWindow.__init__(self,parent,name,fl)
>       self.setCentralWidget(QWidget(self,"qt_central_widget"))
>       self.TabWidgetMain = QTabWidget(self.centralWidget 
> (),"TabWidgetMain")
>       self.SearchTab = QWidget(self.TabWidgetMain,"SearchTab")
>
>       self.SearchCriteriaGroupBox = QGroupBox 
> (self.SearchTab,"SearchCriteriaGroupBox")
>       self.SearchCriteriaGroupBox.setColumnLayout(0,Qt.Vertical)
>       self.SearchCriteriaGroupBox.layout().setSpacing(6)
>       self.SearchCriteriaGroupBox.layout().setMargin(11)
>       SearchCriteriaGroupBoxLayout = QGridLayout 
> (self.SearchCriteriaGroupBox.layout())
>       SearchCriteriaGroupBoxLayout.setAlignment(Qt.AlignTop)
>
>       self.SearchButton = QPushButton 
> (self.SearchCriteriaGroupBox,"SearchButton")
>
>       SearchCriteriaGroupBoxLayout.addWidget(self.SearchButton,1,4)
> ...


> Excerpt from main.py
> =================
> ...
> import ui
>
> class MyMain(ui.Form1, QMainWindow):
>
>     def __init__(self, my_data, parent=None, name=None, fl=0):
>
>         ui.Form1.__init__(self, parent, name, fl)
>
>         self.SearchCriteriaListView = myListView(my_data,  
> self.SearchCriteriaGroupBox, "SearchCriteriaListView")
>         self.SearchCriteriaListView.addColumn('Search Field', 200)
>         self.SearchCriteriaListView.addColumn('Comparison', 200)
>
>         SearchCriteriaGroupBoxLayout.addMultiCellWidget 
> (self.SearchCriteriaListView,0,0,0,4)
> ...

The last line of main.py is where I would like to add  
self.SearchCriteriaListView to SearchCriteriaGroupBoxLayout, but  
there is no way to get to the layout.

Can anyone recommend a workaround besides editing the ui.py file?  Is  
there an option in Designer or pyuic to get around this problem?

Thanks for your help,

Chad




More information about the PyQt mailing list