python - Wrong widget order using vbox layout PyQt -
i trying put qlabel widget on top of (ie before) qlineedit widget edit.
but keeps appearing after qlineedit widget. code,
class centralwidget(qtgui.qwidget): def __init__(self, parent=none): super(centralwidget, self).__init__(parent) # set layouts self.layout = qtgui.qvboxlayout(self) # flags self.randflag = false self.sphereflag = false self.waterflag = false # poly names self.pnames = qtgui.qlabel("import file name", self) # label concerned self.polynameinput = qtgui.qlineedit(self) # line edit concerned # polytype selection self.polytypename = qtgui.qlabel("particle type", self) polytype = qtgui.qcombobox(self) polytype.additem("") polytype.additem("random polyhedra") polytype.additem("spheres") polytype.additem("waterman polyhedra") polytype.activated[str].connect(self.onactivated) self.layout.addwidget(self.pnames) self.layout.addwidget(self.polynameinput) self.layout.addwidget(self.pnames) self.layout.addwidget(self.polytypename) self.layout.addwidget(polytype) self.layout.addstretch() def onactivated(self, text): # loads of clever stuff i'm not @ liberty share class polyhedra(qtgui.qmainwindow): def __init__(self): super(polyhedra, self).__init__() self.central_widget = centralwidget(self) self.setcentralwidget(self.central_widget) # set window self.setgeometry(500, 500, 300, 300) self.setwindowtitle('pyticle') self.show() # combo box def onactivated(self, text): self.central_widget.onactivated(text) def main(): app = qtgui.qapplication(sys.argv) poly = polyhedra() sys.exit(app.exec_()) if __name__ == '__main__': main()
the window below.
what missing? thought qvbox allowed stack things vertically in order add items main widget. (are these sub-widget objects called widgets?)
the problem because adding self.pnames
label layout twice.
#portion of code ... self.layout.addwidget(self.pnames) # here self.layout.addwidget(self.polynameinput) self.layout.addwidget(self.pnames) # , here self.layout.addwidget(self.polytypename) self.layout.addwidget(polytype) self.layout.addstretch() ...
the first time add qlabel
, gets added before lineedit
, when add second time, moves bottom of lineedit
. happens because there 1 object of qlabel
self.pnames
. can added 1 location. if want use 2 labels, consider creating 2 separate objects of qlabel
Comments
Post a Comment