This little caveat has been bothering me for a few hours.

Adding a widget as a child of a parent widget makes it position itself at 
(0, 0). That's fine, I can move it around in resizeEvent. The size of the 
widget is determined by its children - say if the widget is a container for 
a couple of buttons, the amount of buttons and their default sizes govern 
the size of the container.

But, installing a layout onto the parent of the container causes the 
container to seemingly force its children to resize to an inappropriate 
size.

I could imaging that assigning a layout to a parent with children might 
implicitly assign its children to the layout, but that isn't what I would 
expect. Ultimately, I would like to have a completely free-floating widget.

Uncomment the layout line to see what happens. This happens in both PyQt4 
and 5 so I expect to be missing something trivial.


from PyQt4.QtGui import *
from PyQt4.QtCore import *




class Window(QWidget):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)


        menu = QWidget(self)
        menu.setObjectName('Menu')


        btn1 = QPushButton('Hello')
        btn2 = QPushButton('World')


        layout = QBoxLayout(QBoxLayout.LeftToRight, menu)
        layout.addWidget(btn1)
        layout.addWidget(btn2)


        # layout = QBoxLayout(QBoxLayout.TopToBottom, self)


        self.setStyleSheet("#Menu {background-color: darkgray; }")
        self.resize(300, 100)


        
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)


    win = Window()
    win.show()


    sys.exit(app.exec_())

-- 
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/240d1de8-ead1-455a-a344-ff991db44398%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to