views:

323

answers:

1

I'm trying a simple example with Qt Designer and Pyqt4, when I preview the UI in Qt Designer (control+R) it looks good, but when I try to execute the generated UI code, layouts don't work properly and instead of autosizing widgets to the max they are so small that they can't be used.

If I use fixed sizes it works well.

The code used to load the window is:

import sys

from PyQt4 import QtCore, QtGui

from table import Ui_table

class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.ui = Ui_table()
        self.ui.setupUi(self)

def main():
    app = QtGui.QApplication(sys.argv)
    window=Main()
    window.show()

    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

And the Qt Designer xml file to generate the ui code with a simple widget maximized:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>table</class>
 <widget class="QWidget" name="table">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>457</width>
    <height>422</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <widget class="QTreeWidget" name="list">
     <column>
      <property name="text">
       <string>name</string>
      </property>
     </column>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

Any suggestions?

OS: Windows XP
Python: Python 2.6.3
PyQt4: 4.6.1

A: 

This is a long shot, but isn't the code using QMainWindow and the XML ui-descripting defines a QWidget. I'm not sure if that is the problem, but it does not look 100% correct to me.

e8johan