Skip to content

Dialog with loadUi placement inconsistency on show #323

@MagicRedDeer

Description

@MagicRedDeer

Whenever I try to create a Dialog which has an existant active parent Window, the placement of the Dialog on show (or exec_) is dependant upon the binding in question.

For example if have:

#simple_load.py

from __future__ import print_function
import sys

from Qt.QtWidgets import (
        QWidget, QApplication, QVBoxLayout, QPushButton, QDialog)
from Qt.QtCompat import loadUi


class Dialog(QDialog):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent=parent)
        loadUi("untitled.ui", self)
        self.pushButton.clicked.connect(self.close)


class Widget(QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent=parent)
        self.layout = QVBoxLayout(self)
        self.btn = QPushButton('Click')
        self.btn.clicked.connect(self.clicked)
        self.layout.addWidget(self.btn)

    def clicked(self):
        dialog = Dialog(self)
        dialog.exec_()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = Widget()
    widget.show()
    app.exec_()

with untitled.ui as:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>199</width>
    <height>60</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <widget class="QLabel" name="label">
     <property name="text">
      <string>Message</string>
     </property>
    </widget>
   </item>
   <item>
    <widget class="QPushButton" name="pushButton">
     <property name="text">
      <string>OK</string>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

and I do

(py37env) D:\workspace\test>set QT_PREFERRED_BINDING=PySide2;PyQt5
(py37env) D:\workspace\test>python simple_load.py

I will get the second dialog at the top-left corner.

and if I do

(py37env) D:\workspace\test>set QT_PREFERRED_BINDING=PyQt5;PySide2
(py37env) D:\workspace\test>python simple_load.py

I will get the second dialog at the center of the parent window.

For python27 and PySide I get the second window wedged above the top left corner.

if I use the setup_ui function as in baseinstance1.py, I will get the second dialog in the middle of the screen regardless of the binding. This I can manipulate by overridiing showEvent and calling move.
Also that setup_ui does not make the child window be always on top of the parent window.

However, setup_ui and the override seem like just unnecessary inconvenient boiler plate in otherwise somewhat clean Qt.py and should probably be a part of the shim library. Am I wrong to expect consistent behaviour out of the box?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions