Resizing QWidget inside QMainWindow

1,002 views
Skip to first unread message

Panupat Chongstitwattana

unread,
May 17, 2018, 1:26:14 AM5/17/18
to Python Programming for Autodesk Maya
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_()



5_17_2018 , 12_22_07 PM.jpg

Marcus Ottosson

unread,
May 17, 2018, 1:50:29 AM5/17/18
to python_in...@googlegroups.com

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.

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_()

--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6b9b3864-1a4c-43f1-9c1a-23e54bd73bb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages