From 60fb67f792191bf9e2629d7f53589ee1b1c9700d Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Wed, 18 Sep 2019 16:58:29 +0500 Subject: [PATCH 1/3] trying to fix loadUi widget placement issue --- Qt.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Qt.py b/Qt.py index ba9992c0..ae9c5344 100644 --- a/Qt.py +++ b/Qt.py @@ -927,6 +927,23 @@ def load(self, uifile, *args, **kwargs): widget = Qt._QtUiTools.QUiLoader.load( self, uifile, *args, **kwargs) + if self.baseinstance: + + # copy over all the widgets and layouts from attributes + for member in dir(widget): + value = getattr(widget, member) + if isinstance(value, Qt.QtCore.QObject): + setattr(self.baseinstance, member, value) + + # poach main layouts and widgets + if isinstance(widget, Qt.QtWidgets.QMainWindow): + self.baseinstance.setCentralWidget( + widget.centralWidget()) + self.baseinstance.setMenuBar(widget.menuBar()) + self.baseinstance.setStatusBar(widget.statusBar()) + else: + self.baseinstance.setLayout(widget.layout()) + # Workaround for PySide 1.0.9, see issue #208 widget.parentWidget() @@ -942,7 +959,7 @@ def createWidget(self, class_name, parent=None, name=""): if parent is None and self.baseinstance: # Supposed to create the top-level widget, # return the base instance instead - return self.baseinstance + parent = self.baseinstance # For some reason, Line is not in the list of available # widgets, but works fine, so we have to special case it here. From 712dd25e41d7e3fe50514b896f6eaaac6a10f9c9 Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Wed, 18 Sep 2019 19:38:06 +0500 Subject: [PATCH 2/3] Getting the geometry right --- Qt.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Qt.py b/Qt.py index ae9c5344..6efb7ec9 100644 --- a/Qt.py +++ b/Qt.py @@ -928,21 +928,14 @@ def load(self, uifile, *args, **kwargs): self, uifile, *args, **kwargs) if self.baseinstance: - - # copy over all the widgets and layouts from attributes - for member in dir(widget): - value = getattr(widget, member) - if isinstance(value, Qt.QtCore.QObject): - setattr(self.baseinstance, member, value) - - # poach main layouts and widgets - if isinstance(widget, Qt.QtWidgets.QMainWindow): - self.baseinstance.setCentralWidget( - widget.centralWidget()) - self.baseinstance.setMenuBar(widget.menuBar()) - self.baseinstance.setStatusBar(widget.statusBar()) - else: - self.baseinstance.setLayout(widget.layout()) + # correct geometry on show + parent = self.baseinstance.parentWidget() + if parent and hasattr(parent, 'geometry'): + geo = self.baseinstance.geometry() + pgeo = parent.geometry() + self.baseinstance.move( + pgeo.x() + pgeo.width()/2 - geo.width()/2, + pgeo.y() + pgeo.height()/2 - geo.height()/2) # Workaround for PySide 1.0.9, see issue #208 widget.parentWidget() @@ -959,7 +952,7 @@ def createWidget(self, class_name, parent=None, name=""): if parent is None and self.baseinstance: # Supposed to create the top-level widget, # return the base instance instead - parent = self.baseinstance + return self.baseinstance # For some reason, Line is not in the list of available # widgets, but works fine, so we have to special case it here. From e214e381dc8c739c9e37bae8183f42ce0c827144 Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Wed, 18 Sep 2019 20:55:13 +0500 Subject: [PATCH 3/3] better placement --- Qt.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Qt.py b/Qt.py index 6efb7ec9..1ca37a5a 100644 --- a/Qt.py +++ b/Qt.py @@ -930,12 +930,15 @@ def load(self, uifile, *args, **kwargs): if self.baseinstance: # correct geometry on show parent = self.baseinstance.parentWidget() - if parent and hasattr(parent, 'geometry'): + if parent and hasattr(parent, 'frameGeometry'): geo = self.baseinstance.geometry() pgeo = parent.geometry() + pfgeo = parent.frameGeometry() + hdiff = pfgeo.height() - pgeo.height() self.baseinstance.move( - pgeo.x() + pgeo.width()/2 - geo.width()/2, - pgeo.y() + pgeo.height()/2 - geo.height()/2) + pgeo.x() + pgeo.width()/2 - geo.width()/2, + pgeo.y() + pgeo.height()/2 - geo.height()/2 - + hdiff) # Workaround for PySide 1.0.9, see issue #208 widget.parentWidget()