Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog with loadUi placement inconsistency on show #323

Open
MagicRedDeer opened this issue Sep 18, 2019 · 2 comments · May be fixed by #324
Open

Dialog with loadUi placement inconsistency on show #323

MagicRedDeer opened this issue Sep 18, 2019 · 2 comments · May be fixed by #324

Comments

@MagicRedDeer
Copy link

MagicRedDeer commented Sep 18, 2019

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?

@mottosso
Copy link
Owner

I'd say you're in your right to expect consistent behavior here, as Qt.py is meant to do exactly that, not only for functional consistency but visual too.

This seems like a difference in the bindings themselves, and if it's possible to provide consistency out of the box then I think we should.

Are you able to reproduce the problem without a .ui file? That would help narrow down whether it's the UI loader or not.

@MagicRedDeer
Copy link
Author

All I know for now is that if I remove the following lines from override of createWidget from _UiLoader ...

                if parent is None and self.baseinstance:
                    # Supposed to create the top-level widget,
                    # return the base instance instead
                    return self.baseinstance

No widgets from the .ui file show up but the Dialog shows up in the middle of the parent widget.

@MagicRedDeer MagicRedDeer linked a pull request Sep 18, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants