Open
Description
I am using an occ widget on a tab that is initially disabled. When i enable the tab and click on it, the widget appears, however it is not the full size like below. I currently have a fix that requires resizing the window, but I want the widget to automatically resize. I have tried using the resize, MustBeResized, and reset views within the pythonocc-core documentation but it doesn't seem to have any effect. The only way I have gotten it to resize on initialization is by setting it as the current tab from the start, but that will not work for future development because it needs to be the second tab opened.
Here is the widget class that I have created.
class occWidget(qtViewer3d):
def __init__(self, parent=None):
super().__init__(parent)
if parent is None:
return
self.InitDriver()
self._display.display_triedron()
self._display.set_bg_gradient_color([206, 215, 222], [128, 128, 128])
self.context: AIS_InteractiveContext = self._display.GetContext()
self.myQMenuBar = QtWidgets.QMenuBar(self)
self.fileMenu = self.myQMenuBar.addMenu('File')
self.editMenu = self.myQMenuBar.addMenu('Edit')
self.importAction = QtWidgets.QAction('Import Geometry', self)
self.importAction.triggered.connect(self.file_open)
self.fileMenu.addAction(self.importAction)
def InitDriver(self):
winid = int(self.winId()) # assume PyQt5 Window handles
self._display = OCCViewer.Viewer3d(window_handle=winid, parent=self)
self._display.Create()
self._display.SetModeShaded()
self._inited = True
# dict mapping keys to functions
self._key_map = {ord('W'): self._display.SetModeWireFrame,
ord('S'): self._display.SetModeShaded,
ord('A'): self._display.EnableAntiAliasing,
ord('B'): self._display.DisableAntiAliasing,
ord('H'): self._display.SetModeHLR,
ord('F'): self._display.FitAll,
ord('G'): self._display.SetSelectionMode,
}
self.createCursors()
self.view = self._display.GetView()
def resizeEvent(self, event):
if self._inited:
super().resizeEvent(event)
self._display.OnResize()
def file_open(self):
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
"Select CAD File",
"",
"All Files (*);;Python Files (*.py)",
options=options)
if file_name and 'igs' in file_name:
print(file_name)
shape = read_iges_file(file_name)
self._display.DisplayShape(shape, update=True)
else:
msg = QtWidgets.QMessageBox()
msg.setWindowTitle('File Type Error')
msg.setText('Wrong file type. Choose "igs" file')
msg.exec_()