python - pyqt - position child widget from qt designer near parent -
i use qt designer
create child widget (layout) - tree_view_widget_ui.py
class ui_form(object): def setupui(self, form, parent = none): form.setobjectname(_fromutf8("form")) form.setenabled(true) form.resize(200, 300) form.setminimumsize(qtcore.qsize(200, 300)) self.gridlayout = qtgui.qgridlayout(form) self.gridlayout.setobjectname(_fromutf8("gridlayout")) self.treewidget = qtgui.qtreewidget(form) self.treewidget.setenabled(true) self.treewidget.setminimumsize(qtcore.qsize(200, 300)) font = qtgui.qfont() self.treewidget.setfont(font) self.treewidget.setdragdropmode(qtgui.qabstractitemview.dragdrop) self.treewidget.setobjectname(_fromutf8("treewidget")) self.treewidget.headeritem().settext(0, _fromutf8("1")) self.gridlayout.addwidget(self.treewidget, 0, 0, 1, 1) self.retranslateui(form) qtcore.qmetaobject.connectslotsbyname(form) def retranslateui(self, form): form.setwindowtitle(_translate("form", "tree view", none)) self.treewidget.setsortingenabled(true)
and initialize child user-interface in tree_view_widget.py
from tree_view_widget_ui import ui_form class treeviewwidget(qwidget): def __init__(self, parent=none, flags=0): super(treeviewwidget, self).__init__(parent) self.ui = ui_form() self.ui.setupui(self, parent = parent)
and child widget intialized parent main.py
, opened signal:
# tree widget tree_view_widget.tree_view_widget import treeviewwidget class mainwindow(qtgui.qmainwindow): def __init__(self): super(mainwindow, self).__init__() self.flags = qtcore.qt.window # tree view widget self.treeviewwidget = treeviewwidget(parent=self) self.treeviewwidget.setwindowflags(self.flags) self.treeviewwidget.show()
my question is: how can position child widget near parent widget top left/right corners coincide , not modifying file tree_view_widget_ui.py
code automatically generated qt designer
. managed position child widget target location when modifying file tree_view_widget_ui.py
avoid if possible.
in class mainwindow
:
you want use self.treeviewwidget.setgeometry(x, y, width, height)
or use move(x, y) function.
see docs setgeometry , move functions
Comments
Post a Comment