Design crushing to corner and failing to layout PyQT5



  • I'm kinda new to this so I'm basically just copy pasting the stuff from tutorials I've done to make it work.

    I've made a designer.ui file with QtDesigner and now I've exported it to Python code. If I use the -x command then run the design Python it works fine, but if I import it to another file (so I can make connections) then it all crushes down to 1 place rather than sticking to the grid layout base.

    If I launch my Main.py file (not designer code) then I get the error QLayout: Attempting to add QLayout "" to MainWindow "MainWindow", which already has a layout but I don't see where I'm adding a layout within my Main code...

    My code is: https://gist.github.com/crabcrabcam/3a6a9e847791117616d18ada0895f868

    Thanks for any help :) If you need some more stuff just ask.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    self.gridLayout = QtWidgets.QGridLayout(MainWindow) in your MainDes.py triggers the message. Passing a widget as parent of the layout will make the layout applied to that widget. QMainWindow already has the layout that implements all the features like dock handling etc.

    On a side note, why QtWidgets.QWidget.__init__(self, parent) and not QtWidgets.QMainWindow.__init__(self, parent) in Main.py ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.