0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Substance 3D Painter にツールバーを追加する

Posted at

環境

  • Windows
  • Adobe Substance 3D Painter 10.1.2

ツールバーの追加

Substance 3D Painterにメニューを追加する」に関連する内容です。
Substance 3D Painter ではメニューだけでなくツールバーも追加可能です。

参考イメージ

toolbar_00.jpg

サンプルコード

以下のコードは説明のわかりやすさを重視したものです。コーディングのベストプラクティスを示したものではありませんのでご注意ください。

from functools import partial

from PySide6 import QtGui

import substance_painter as sp

plugin_widgets = []


def start_plugin():
    toolbar = sp.ui.add_toolbar("Sample", "Sample", sp.ui.UIMode.Edition)

    action1 = toolbar.addAction(QtGui.QIcon("red.png"), "red")
    action1.triggered.connect(partial(echo, "red"))
    action2 = toolbar.addAction(QtGui.QIcon("green.png"), "green")
    action2.triggered.connect(partial(echo, "green"))
    action3 = toolbar.addAction(QtGui.QIcon("blue.png"), "blue")
    action3.triggered.connect(partial(echo, "blue"))

    plugin_widgets.append(toolbar)


def close_plugin():
    for widget in plugin_widgets:
        sp.ui.delete_ui_element(widget)
    plugin_widgets.clear()


def echo(s):
    print(s)


if __name__ == "__main__":
    start_plugin()

説明

プラグインの基本的な記述方法は「 Substance 3D Painterにメニューを追加する」 をご覧ください。
Substance 3D Painter でツールバーを追加するのには ui moduleadd_toolbar 関数を使用することが重要です。こちらを使用すると、Substance 3D Painter のメインウインドウにツールバーを追加してくれます。返り値として QToolBar が返ってくるので、後はこれに Qt for Python と同じ方法で QToolBar にボタンを追加するコードを書けば問題ありません。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?