你能告诉我如何在 NUKE 中创建没有间距的自定义面板(即无框窗口)吗?
目前它看起来像这样:
但我需要它看起来像这样:
发生这种情况是因为面板有几个嵌套的小部件,每个小部件都添加了自己的边距,因此您需要遍历父小部件并在每个小部件上设置内容边距。
"""
Get rid of the margins surrounding custom Panels
"""
import nuke
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from nukescripts import panels
def set_widget_margins_to_zero(widget_object):
if widget_object:
target_widgets = set()
target_widgets.add(widget_object.parentWidget().parentWidget())
target_widgets.add(widget_object.parentWidget().parentWidget().parentWidget().parentWidget())
for widget_layout in target_widgets:
try:
widget_layout.layout().setContentsMargins(0, 0, 0, 0)
except:
pass
class Example_Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
layout = QtGui.QVBoxLayout()
label = QtGui.QLabel('Margins be-gone!')
label.setStyleSheet('QLabel{background: #eeffcc}')
layout.setContentsMargins(0,0,0,0)
layout.addWidget(label)
self.setLayout(layout)
expandingPolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
label.setSizePolicy(expandingPolicy)
self.setSizePolicy(expandingPolicy)
def event(self, event):
if event.type() == QtCore.QEvent.Type.Show:
try:
set_widget_margins_to_zero(self)
except:
pass
return QtGui.QWidget.event(self, event)
panels.registerWidgetAsPanel('Example_Window', 'Example Widget',
'mwbp.Example_Widget')
为了给予应有的荣誉,我不久前在这里找到了解决方案:https ://gist.github.com/maty974/4739917并发布了一个集成的示例小部件。
我知道通过 Python 制作面板的唯一方法是这样(但它带有框架):
class myCustomPanel( nukescripts.PythonPanel ):
def __init__( self ):
nukescripts.PythonPanel.__init__( self, 'myCustomPanel' )
self.update = nuke.PyScript_Knob( 'update', 'Update Info' )
self.info = nuke.Multiline_Eval_String_Knob( 'info', 'Info' )
self.info.setEnabled( True )
self.addKnob( self.update )
self.addKnob( self.info )
def addInfoPanel():
global iPanel
iPanel = myCustomPanel()
return iPanel.addToPane()
paneMenu = nuke.menu( 'Pane' )
paneMenu.addCommand( 'myCustomPanel', addInfoPanel )