QMainWindow is for special circumstances where the layout and contents of your window fits with the Qt concept of what a “Main Window” is, which is this.
- http://doc.qt.io/qt-5/qmainwindow.html#details If you aren’t interested in most of that, then QDialog is probably what you want instead. To answer your question, you’ll need to assign the “central widget”, like this: ... centralwidget = QtGui.QWidget() mainwin = QtGui.QMainWindow() mainwin.setCentralWidget(centralwidget) vLayout = QtGui.QVBoxLayout(centralwidget) mywidget = LayerInfoWidget(parent=mainwin) vLayout.addWidget(mywidget) mainwin.show() mainwin.raise_() On 17 May 2018 at 06:26, Panupat Chongstitwattana <[email protected]> wrote: > I'm trying to add QWidget to a QMainWindow but I cannot figure out how to > make it resize properly. > > Top - if I show the widget by itself. > Bottom - the widget added to QMainWindow. > > Am I doing something wrong? > > > > class LayerInfoWidget(QtGui.QWidget): > def __init__(self, parent = None): > super(LayerInfoWidget, self).__init__(parent) > > self.hLayout = QtGui.QHBoxLayout(self) > > > > self.label = QtGui.QLabel(self) > > self.label.setText('Pass Name Here') > > self.enabled = QtGui.QCheckBox(self) > self.enabled.setChecked(True) > > self.frameList = QtGui.QLineEdit(self) > self.frameList.setText('1-10') > > self.passName = QtGui.QLineEdit(self) > self.passName.setText('Filename - PASS') > > self.hLayout.addWidget(self.label) > self.hLayout.addWidget(self.enabled) > self.hLayout.addWidget(self.frameList) > self.hLayout.addWidget(self.passName) > > self.setLayout(self.hLayout) > > > > mainwin = QtGui.QMainWindow() > vLayout = QtGui.QVBoxLayout(mainwin) > mywidget = LayerInfoWidget(parent=mainwin) > vLayout.addWidget(mywidget) > mainwin.setLayout(vLayout) > > mainwin.show() > mainwin.raise_() > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/python_inside_maya/6b9b3864-1a4c-43f1-9c1a- > 23e54bd73bb1%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/6b9b3864-1a4c-43f1-9c1a-23e54bd73bb1%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB8s1buLWQrvnNJneg5E87mqpDgiQ0bYpFW%3DcDd4P70uQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
