python - PyQt4: How to auto adjust size of a widget not in layout -


i want implement gui program blueprint editor in unreal game engine pyqt4. here example of blueprint editor:

enter image description here

first create simple container widget place components(the rectangles). in order allow user place rectangles wherever want(by drag & drop), can't place widgets in layout. when content of rectangle changed, rectangle widget can't auto adjust size itself.

following example code:

import sys  pyqt4 import qtcore pyqt4 import qtgui   class changeablechild(qtgui.qwidget):     def __init__(self, parent=none):         super(changeablechild, self).__init__(parent)         self.setlayout(qtgui.qvboxlayout())      def addwidget(self, widget):         self.layout().addwidget(widget)   class mainwidget(qtgui.qwidget):     def __init__(self, child, parent=none):         super(mainwidget, self).__init__(parent)         child.setparent(self)  def main():     app = qtgui.qapplication(sys.argv)     changeable_child = changeablechild()     button = qtgui.qpushbutton("add label")     changeable_child.addwidget(button)     win = mainwidget(changeable_child)     win.show()     button.clicked.connect(         lambda: changeable_child.addwidget(qtgui.qlabel("a label.")))      app.exec_()   if __name__ == "__main__":     main()  

when hit "add label" button add new label. size of changeablechild wouldn't change automatically. if put changeablechild in layout, it's good.

so there way auto adjust widget when it's not in layout? or there way can place widget in layout , still can place in absolute position?


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -