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 python_inside_m...@googlegroups.com.
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.
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.
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')
# menu.resize(500, 200)
btn1 = QPushButton('Hello')
btn2 = QPushButton('World')
for wid in (btn1, btn2, menu):
wid.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
layout = QBoxLayout(QBoxLayout.LeftToRight, menu)
layout.addWidget(btn1)
layout.addWidget(btn2)
layout.setSizeConstraint(QLayout.SetNoConstraint)
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_())
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
The size of the parent widget is not necessarily determined by its children. It *can* be determined by its children if a layout is installed and there are no overruling size contraints being applied to the parent. If you make widgets children of another, without a layout, they are all allowed to overlap and be cropped off by the parent. It is only the layout engine that constantly observes the children to manage the size of the parent.
I would actually expect it not to mess with the layout assignments of existing children, when adding a layout. There are times when you want both layout constrained children, an floating positioned children.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7b734a21-6b88-4f3c-ab1c-37e034038a84%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2aJCwAQ%3DbgONtxWT78zuZYG78eJZcCUzX4jSGCO9UPPQ%40mail.gmail.com.
Yea probably because of the adjustSize that may get recursively triggered.
If you want to keep it stuck to the width of the parent but have full controll of its position then you could manage it from the parents resizeEvent()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODVm0BAmFz-0nr0MZ4wLeWr0PSywbDU6b0tzYGfWCjDsA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0nMkyvwXOY49mQbyjjUnDhJ5McvkSL7qhGN67kZPSLWw%40mail.gmail.com.