PyQt5 / PyQt

PyQt Examples(PyQt各种测试和例子) PyQt4 PyQt5
GNU Lesser General Public License v2.1
6.64k stars 1.96k forks source link

QDialog crashes when dragged across two monitors when resizing is disabled. [讨论] #162

Closed HannesLum closed 2 years ago

HannesLum commented 2 years ago

When the flag Qt.MSWindowsFixedSizeDialogHint is set, the widget crashes, when it is dragged from one monitor to another. Here is a minimal example that creates this behaviour and the following is a closer explanation of the behaviour:

When dragging certain widgets across two monitors of different sizes, they get resized automatically, as any other window, but the widgets then the widgets enter an infinite resizing loop and become unresponsive until python crashes. In order to reproduce this issue, the hardest part might be that you need two incompatible screens. Both of my screens have a resolution of 1920x1080 but their size in inches/cm is different. I'm not sure how my Windows 10 OS handles this exactly, but all windows are resized when dragged from one screen to another, so that for example text has a readable size. Trying this with the minimal example, will result in a freezing of the QDialog widget.

To be more exact my left monitor is the smaller one. This might be important because the window size is determined by the center point of the window, and i think for certain widgets they don't resize around the center point, but are a little left-bound. I believe it has something to do with the resizing of the widget text changing the width of the widget, because a common trait of the affected widgets where i found this issue are texts spanning until the left border of their hBox or vBox, but i can't know for sure, as there are also widgets with stranger behaviour.

Environment

892768447 commented 2 years ago

Sorry to see this problem so late. If you want fixed size dialog, There are three ways

  1. Qt.MSWindowsFixedSizeDialogHint
  2. setMinimumSize and setMaximumSize
  3. dialog.setFixedSize

Try them again, the crash problem, I will debug it later

892768447 commented 2 years ago

left: 1920x1080 100% right: 1920x1080 125%

Slowly drag the window between the two screens

image

892768447 commented 2 years ago

I think this Qt's or windows bug is caused by using 'MSWindowsFixedSizeDialogHint' and 'setFixedSize' of the top-level layout at the same time.

because remove MSWindowsFixedSizeDialogHint, use os.environ['QT_SCALE_FACTOR'] = '1.0' or a.setAttribute(Qt.AA_EnableHighDpiScaling, False) , the problem is still exist.

HannesLum commented 2 years ago

Oh, so it is a Qt or windows bug after all. Thank you for the help!

892768447 commented 2 years ago

see https://github.com/biolab/orange3/issues/6040#issuecomment-1167004959