tpaviot / pythonocc-demos

Examples and demos for the pythonocc CAD package
216 stars 115 forks source link

Example for automatically sizing the Display3d widget? #72

Closed nsmela closed 10 months ago

nsmela commented 10 months ago

Hi there,

I'm having a hard time getting the display in PyQt5 to fully fit into a window. If I resize the window, it then works great.

I've tried:

Any other suggestions?

tpaviot commented 10 months ago

The resize event has to be raised from PyQtitself. See for instance https://github.com/tpaviot/pythonocc-core/blob/master/src/Display/SimpleGui.py#L213 where I have to set the window size twice to get sure the occ widget fit the parent window.

tpaviot commented 10 months ago

So far, I did not find any better solution

nsmela commented 10 months ago

Thanks! I think you linked to a function to centre the window. Did you mean https://github.com/tpaviot/pythonocc-core/blob/master/src/Display/SimpleGui.py#L234?

nsmela commented 10 months ago

Given the example there, I created a function for my window:

def showProperly(self):
        size = [self.size().width(), self.size().height()]
        self.resize(size[0]-1, size[1]-1)
        self.show()
        self.resize(size[0], size[1])

I couldn't call the window.show() function the same way since I'm using a splash screen, so I use this function instead of calling window.show() in the main file.