python - 如何在Nuke中通过Python创建无框架的自定义面板?

标签 python pyqt pyqt4 nuke

你能告诉我如何在 NUKE 中创建没有间距的自定义面板(即无框窗口)吗?

目前看起来像这样:

enter image description here

但我需要它看起来像这样:

enter image description here

最佳答案

发生这种情况是因为面板有几个嵌套的小部件,每个小部件都添加了自己的边距,因此您需要迭代父小部件并在每个小部件上设置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/

相关文章:

python - dejavu.py 识别的歌曲的附加信息

Python enum34 类似 boost python enum 的接口(interface)

python - 在 QTreeWidget 中升高和降低 QTreeWidgetItem?

python - 在选项卡之间传递变化的数据

python - 如何在 pyqt4 python 中捕获关闭信号?

python - 在 Python 中基于一个属性合并两个嵌套列表

python - 如何使用 pyparsing 解析带有撇号的语言?

python - 捕获 QApplication 中引发的异常

python - PyQt OpenGL : drawing simple scenes

python - pyQt4 - 如何选择表格行并禁用编辑单元格