0

I created a form in qt designer and I wanted to make it stretch when resizing the window.

I found out it requires central widget to be placed in a layout. And indeed when I added my top level layout and preview the form it qt designer it looks and behaves exactly as I want. But when I convert it to .py with pyuic5 and run from python it doesn't display properly anymore. All the widgets from the top level layout are stacked on each other in the top left corner.

When I break this layout (no other modifications) and rerun pyuic5 it works again except from the stretching when resizing the window.

EDIT:

Turns out the problem I had was not the form itself, but that I built a Widget in Qt Designer, and then my main class was inheriting from MainWindow:

class MyApp(QtWidgets.QMainWindow):

    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)

When I changed this inheritance to QWidget it works as expected now. I'm guessing it has something to do with the fact that Main Window has menu bar and status bar except from central widget?

MJB
  • 793
  • 1
  • 11
  • 25
  • Publish your sample `.ui` file – S. Nick Dec 28 '18 at 09:22
  • The linked post does not have an answer to my question. My question is about how to make GUI stretch when resizing the window and my edit says that I found a fix, by changing the parent class from QMainWindow to QWidget, although the original question did not have enough information to make that deducible. – MJB Jan 07 '19 at 16:04

0 Answers0