取决于您的期望,您可以在转出控件中使用 .NET 按钮但您必须自己设置样式以匹配主题并使用系统样式使其看起来像 maxscript 按钮:
try destroyDialog testRol catch()
rollout testRol "MXS + .NET"
(
dotNetControl btnMakeCylinder "Button" text:"&Make Cylinder" width:120 height:25
on btnMakeCylinder mouseClick evnt arg do with undo on Cylinder isSelected:on
on testRol open do btnMakeCylinder.FlatStyle = btnMakeCylinder.FlatStyle.System
)
createDialog testRol
或者您可以使用 MaxForm,其中按钮将继承颜色,但它仍然不会像 UI 的其余部分:
(
local form = dotNetObject "MaxCustomControls.MaxForm"
form.Text = ".NET form"
fn makeCylinder = with undo on Cylinder isSelected:on
local btnMakeCylinder = dotNetObject "Button"
btnMakeCylinder.Text = "&Make Cylinder"
dotNet.addEventHandler btnMakeCylinder "MouseClick" makeCylinder
form.Controls.Add btnMakecylinder
form.ShowModeless()
)
或者您可以使用 Qt UI,它有自己的一系列缺点(例如必须始终显式指定撤消记录),而且它相当冗长:
(
local legacy = (python.import "sys").version_info[1] < 3
local QtGui = python.import "PySide2.QtGui"
local QtWidgets = python.import "PySide2.QtWidgets"
local GetQMaxMainWindow = (if legacy then python.import "MaxPlus" else python.import "qtmax").GetQMaxMainWindow
if isProperty ::testQtDialog #close do testQtDialog.close()
testQtDialog = QtWidgets.QDialog(GetQMaxMainWindow())
testQtDialog.setWindowTitle "Qt Window"
local dialogLayout = QtWidgets.QVBoxLayout()
fn makeCylinder = with undo on Cylinder isSelected:on
local btnMakeCylinder = QtWidgets.QPushButton "&Make Cylinder"
btnMakeCylinder.clicked.connect makeCylinder
dialogLayout.addWidget btnMakeCylinder
testQtDialog.setLayout dialogLayout
testQtDialog.show()
)
从 2022 年开始,您还可以通过这种方式使用本机最大控件制作 Qt 窗口:
if isKindOf testQtRol RolloutClass do UIAccessor.closeDialog testQtRol.hwnd
rollout testQtRol "Qt Rollout"
(
QtButton btnMakeCylinder "&Make cylinder" row:0 column:2
on btnMakeCylinder pressed do with undo on Cylinder isSelected:on
)
createQtDialog testQtRol