import shiboken2 import PySide2.QtWidgets as qtw def get_viewer_widget(): main_widget = hou.qt.mainWindow() for widget in main_widget.findChildren(qtw.QWidget, 'RE_Window'): if widget.windowTitle() == 'DM_ViewLayout': for l in widget.findChildren(qtw.QVBoxLayout): if l.count()==1: w = l.itemAt(0).widget() if w.objectName() == 'RE_GLDrawable': i = long(shiboken2.getCppPointer(w)[0]) mouse_widget = shiboken2.wrapInstance(i, qtw.QWidget) return mouse_widget
Stackenblocken-Sidefxsame result
What happens if you cast the widget pointer to int instead of long?
print shiboken2.isValid(get_viewer_widget())
import hou import shiboken2 from PySide2.QtWidgets import * class ViewerWidget(object): def __init__(self): self.viewer = None self.main_window = None def get_viewer_widget(self): # store main window otherwise its widget are destroyed self.main_window = hou.qt.mainWindow() for widget in self.main_window.findChildren(QWidget, 'RE_Window'): if widget.windowTitle() == 'DM_ViewLayout': DM_ViewLayout = widget break else: print('Cannot find DM_ViewLayout') return for l in DM_ViewLayout.findChildren(QVBoxLayout): if l.count()!=1: continue w = l.itemAt(0).widget() if w.objectName() == 'RE_GLDrawable': i = long(shiboken2.getCppPointer(w)[0]) self.viewer = shiboken2.wrapInstance(i, QWidget) return x = ViewerWidget() x.get_viewer_widget() print(shiboken2.isValid(x.viewer)) # check if it is valid print(x.viewer.width())
def getViewportRenderViewPosSize(): qtWindow = hou.ui.mainQtWindow() for w in qtWindow.findChildren(QtWidgets.QWidget, "RE_Window"): if w.windowTitle() == "UI_Viewport": for w2 in w.findChildren(QtWidgets.QVBoxLayout): if w2.count() == 1: w = w2.itemAt(0).widget() if w.objectName() == 'RE_GLDrawable': return w.mapToGlobal(w.pos()), w.size() if w.windowTitle() == "DM_ViewLayout": for w2 in w.findChildren(QtWidgets.QVBoxLayout): if w2.count() == 1: w = w2.itemAt(0).widget() if w.objectName() == 'RE_GLDrawable': return w.mapToGlobal(w.pos()), w.size() return None, None
Qt Warn: External WM_DESTROY received for QWidgetWindow(0xabc3e320, name="RE_WindowWindow") , parent: QWindow(0x0) , transient parent: QWindow(0x0) Qt Warn: External WM_DESTROY received for QWidgetWindow(0x6c4ba2c0, name="RE_WindowWindow") , parent: QWindow(0x0) , transient parent: QWindow(0x0) Traceback (most recent call last): File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraph.py", line 165, in handleEventCoroutine pending_actions) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraph.py", line 1240, in handleEvent uievent.editor, output_index) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 1426, in createInfoWindow force_cook, output_index) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 868, in display self.update(node, pinnable, recook, output_index) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 922, in update verbose=verbose, debug=debug) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 452, in update templatefile, showall=self.showall, **kwargs File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 428, in update self.set_html(html) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 414, in set_html self.htmlarea.setHtml(html) File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.287/houdini/python2.7libs\nodegraphui.py", line 155, in setHtml super(HtmlArea, self).setHtml(html) RuntimeError: Internal C++ object (HtmlArea) already deleted.
def initializeSession(): window = hou.ui.mainQtWindow() window.showFullScreen() hdefereval.execute_deferred(initializeSession)
name = "my_panel_name" app = QtGui.QGuiApplication.instance() mypanel = None allWidgets = app.allWidgets() for w in allWidgets: if name in w.windowTitle(): mypanel = w break;
animatrix_hi animatrix,
o install shiboken2 manually?
from hutil.Qt import shiboken2
import shiboken2
julien-b
Hi guys,
I'm trying to do the same for the network Editor, but even going (recursively) through all the Qt widgets from the hou.qt.mainWindow(), I can't find the right widget ...
Any thought ?
Thanks a lot,
Julien
def getWidgetByName(name): if not hasattr(hou.session, "mainQtWindow"): hou.session.mainQtWindow = hou.qt.mainWindow() hasHandle = hasattr(hou.session, name) if not hasHandle or (hasHandle and getattr(hou.session, name) and not shiboken2.isValid(getattr(hou.session, name))): allWidgets = QtWidgets.QApplication.allWidgets() for w in allWidgets: if name in w.windowTitle(): i = int(shiboken2.getCppPointer(w)[0]) qw = shiboken2.wrapInstance(i, QtWidgets.QWidget) setattr(hou.session, name, qw) w.setParent(hou.session.mainQtWindow, QtCore.Qt.Tool) break if not hasattr(hou.session, name): return None return getattr(hou.session, name)
mabelzile
FYI, hou.SceneViewer.qtWindow() was added in 19.0
https://www.sidefx.com/docs/houdini19.0/hom/hou/SceneViewer.html#qtWindow [www.sidefx.com]