slaclab / pydm

Python Display Manager
http://slaclab.github.io/pydm/
Other
111 stars 76 forks source link

Rezising the main windows failed #958

Open epaiser opened 1 year ago

epaiser commented 1 year ago

Hi guys, I'm in face a problem that could be related to some bug.

When design a widget application with designer using a PyDMEmbeddedDisplay initially hidden with a PushButton to show it and resize the main window or hide and resize back to the initial geometry, after show the EmbeddedDisplay and resize bigger the main window not return back to the initial (smaller) size when I issue hide EmbeddedDisplay and resize self.

I did the same exactly exercise without calling pydm (using pure PyQt) and it works.

I'm attaching both versions (working without pydm and not working with pydm). Designer has the same geometry and layout for both.

Please run and try this two attached simple code.

Someone could help on this issue?

Thank you

with_pydm.zip without_pydm.zip

jbellister-slac commented 1 year ago

Sure, I can take a look today

jbellister-slac commented 1 year ago

So the difference between the two cases is that your pure PyQt version uses a QWidget as the top level object and that is what self is referring to in the resize calls, whereas pydm uses a QMainWindow, of which Display is just a widget within that window, and so self there is referring to that display widget only rather than the main window.

So when you call setFixedHeight in the pure PyQt version, it is essentially setting the height of the whole window. In the pydm version, it is only setting the height of that specific widget, and Qt won't shrink the whole window back down when you resize that widget only. (Can reproduce the basic pydm behavior in the pyqt example by setting the height of self.widget rather than self, can pretty much exactly recreate the behavior by also setting it to inherit from QMainWindow and breaking the layout in designer)

But the bottom line is what you probably want for pydm is to use self.window().setFixedHeight() That will give you a handle on the main window which will then resize everything as you want.