Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:55:21+00:00 2026-05-16T13:55:21+00:00

I’m having an annoyingly stubborn problem here, and I would appreciate it if anyone

  • 0

I’m having an annoyingly stubborn problem here, and I would appreciate it if anyone could give me some insight into what I’m doing wrong.

I have a PyQt app that is supposed to display a table of numbers. So, naturally, I am using QTableWidget. Right now, it’s extremely simple: all I do is create a window with a Table Widget and a button and display it. I am not populating the table at all yet.

I want the table to be able to resize automatically with the window, and eventually I am going to add other widgets to this form, so I am using QGridLayout. And when I preview the form in Qt Designer, it looks and behaves correctly. The Table takes up all of the form except for the space used by the button, and when I resize the window they both resize correctly along with it. But when I try to run the generated Python code, it’s all screwed up. The Table Widget and the button are both scrunched up together, on top of each other, in the top left corner of the window.

I created the .ui file using Qt Designer 4, and generated the Python code using pyuic4. I haven’t edited either of the files manually at all. So I assume that there are no basic syntax errors in either. My guess is that I am somehow misunderstanding the relationship between the widgets, the window and the layout manager. But I cannot figure out how.

Here is the code for my .ui file:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>TableWindow</class>
 <widget class="QWidget" name="TableWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>586</width>
    <height>383</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="windowTitle">
   <string/>
  </property>
  <layout class="QGridLayout" name="gridLayout">
   <item row="0" column="0">
    <widget class="QTableWidget" name="tableWidget"/>
   </item>
   <item row="1" column="0">
    <widget class="QPushButton" name="btnSave">
     <property name="text">
      <string>Save to File</string>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

And here is the Python code generated from the .ui file by pyuic4:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file
'ui_table_window.ui'
#
# Created: Mon Apr 19 23:47:43 2010
#      by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_TableWindow(object):
    def setupUi(self, TableWindow):
        TableWindow.setObjectName("TableWindow")
        TableWindow.resize(586, 383)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                                 QtGui.QSizePolicy.Expanding)
       sizePolicy.setHorizontalStretch(0)
       sizePolicy.setVerticalStretch(0)

sizePolicy.setHeightForWidth(TableWindow.sizePolicy().hasHeightForWidth())
        TableWindow.setSizePolicy(sizePolicy)
        self.gridLayout = QtGui.QGridLayout(TableWindow)
        self.gridLayout.setObjectName("gridLayout")
        self.tableWidget = QtGui.QTableWidget(TableWindow)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)
        self.gridLayout.addWidget(self.tableWidget, 0, 0, 1, 1)
        self.btnSave = QtGui.QPushButton(TableWindow)
        self.btnSave.setObjectName("btnSave")
        self.gridLayout.addWidget(self.btnSave, 1, 0, 1, 1)

        self.retranslateUi(TableWindow)
        QtCore.QMetaObject.connectSlotsByName(TableWindow)

    def retranslateUi(self, TableWindow):
        self.btnSave.setText(QtGui.QApplication.translate("TableWindow", "Save to File", None, QtGui.QApplication.UnicodeUTF8))

Can anyone see what I might be doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:55:22+00:00Added an answer on May 16, 2026 at 1:55 pm

    I would like to know the answer to this question also.

    “It must be in your setup” is zero help.

    SOLVED!

    Addendum: The tasks and statements below are legitimate. However they apply if you have created your dialog/UI as a dialog and/or widget. That in itself is where the probelem lies

    For the proper layout to work and give you the desired form layout, you must start your ui project as a “MainWindow” app. Not the Dialog with buttons or Widget app. The MainWindow template comes prepared with a “centralWidget”, thus giving your layout option. So if you did not, below will help you change that

    It does seem pyuic4 falls short on this one aspect. A way to give the over all ui a wrapper to hook into the main window is to finalize all your widgets by setting them into an over-all layout. QGridLayout, QVerticalLayout, it doesn’t matter, just so that all the contents of the UI are “handled” by a top-level layout. Do NOT apply a layout to the form.

    Note: You may want to temporarily just to be able to use the “preview” in the QT Designer. However this is where the py conversion is broken. You will need to break/remove the form’s layout before saving/converting

    Once you save the .ui file and convert it to your .py file using pyuic4, you will need to add/change a line or two

    from PyQt4 import QtCore, QtGui
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(625, 448)
    
                   <create a "holder" central widget>
            self.widget = QtGui.QWidget()
    
                   <set the overall QLayout with the widget as the>
                   <parent   rather than the "Dialog" that the>
                   <generated code gives you>
            self.gridLayout_2 = QtGui.QGridLayout(self.widget)
    
            self.gridLayout_2.setObjectName("gridLayout_2")
            ....
            ....
    

    Now in the normal modules you will call this UI
    objects.setCentralWidget() function to set that widget

    if __name__ == "__main__":
            app = QtGui.QApplication(sys.argv)
            myapp = MyForm()
            < set the widget inside the form to it's cetral widget >
            myapp.setCentralWidget( myapp.ui.widget )
    
            myapp.show()
            sys.argv[1] = myapp.unUNCPath( sys.argv[1] )
            os.chdir( sys.argv[1] )
            myapp.setRootDir( sys.argv[1] )
            myapp.processDirectory()
            sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.