Python Reference Guide
 
Loading...
Searching...
No Matches
UI\ToolNativeWidgetHolder.py
1# Copyright 2012 Autodesk, Inc. All rights reserved.
2# Use of this software is subject to the terms of the Autodesk license agreement
3# provided at the time of installation or download, or which otherwise accompanies
4# this software in either electronic or hard copy form.
5#
6# Script description:
7# Create a tool that demo how to embed native Qt widgets created by PySide6 into MoBu framework.
8#
9# Topic: FBWidgetHolder, FBTool
10#
11
12from pyfbsdk import *
13from pyfbsdk_additions import *
14try:
15 from PySide6 import QtWidgets
16 from shiboken6 import wrapInstance, getCppPointer
17except:
18 from PySide2 import QtWidgets
19 from shiboken2 import wrapInstance, getCppPointer
20
21#
22# Subclass FBWidgetHolder and override its WidgetCreate function
23#
24class NativeWidgetHolder(FBWidgetHolder):
25 #
26 # Override WidgetCreate function to create native widget via PySide.
27 # \param parentWidget Memory address of Parent QWidget.
28 # \return Memory address of the child native widget.
29 #
30 def WidgetCreate(self, pWidgetParent):
31 #
32 # IN parameter pWidgetparent is the memory address of the parent Qt widget.
33 # here we use wrapInstance() function to convert it to QtWidget object.
34 # and use it the as the parent for native Qt widgets created via Python.
35 # Similiar approach is available in the sip python module for PyQt
36 #
37 # Only a single widget is allowed to be the *direct* child of the IN parent widget.
38 #
39 self.mNativeQtWidget = QtWidgets.QPushButton("Push Button", wrapInstance(pWidgetParent, QtWidgets.QWidget))
40
41 #
42 # return the memory address of the *single direct* child QWidget.
43 #
44 return getCppPointer(self.mNativeQtWidget)[0]
45
46class NativeQtWidgetTool(FBTool):
47 def BuildLayout(self):
48 x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
49 y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
50 w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
51 h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
52 self.AddRegion("main","main", x, y, w, h)
53 self.SetControl("main", self.mNativeWidgetHolder)
54
55 def __init__(self, name):
56 FBTool.__init__(self, name)
57 self.mNativeWidgetHolder = NativeWidgetHolder();
58 self.BuildLayout()
59 self.StartSizeX = 600
60 self.StartSizeY = 400
61
62gToolName = "NativeQtWidgetTool"
63
64#Development? - need to recreate each time!!
65gDEVELOPMENT = True
66
67if gDEVELOPMENT:
68 FBDestroyToolByName(gToolName)
69
70if gToolName in FBToolList:
71 tool = FBToolList[gToolName]
72 ShowTool(tool)
73else:
74 tool=NativeQtWidgetTool(gToolName)
75 FBAddTool(tool)
76 if gDEVELOPMENT:
77 ShowTool(tool)
Tool class.
Definition: pyfbsdk_generated.h:20040
Native Widget Holder (can be used to embed native Qt Widget inside MoBu UI elements) A Widget holder ...
Definition: pyfbsdk_generated.h:21386