最佳答案
发生这种情况是因为面板有几个嵌套的小部件,每个小部件都添加了自己的边距,因此您需要迭代父小部件并在每个小部件上设置ContentsMargins。
"""
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 - 如何在Nuke中通过Python创建无框架的自定义面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224402/