![見出し画像](https://assets.st-note.com/production/uploads/images/147983862/rectangle_large_type_2_0fbbacc0887e10bcaad88fab802e2f96.png?width=1200)
3dsMaxのPySideでStatusBar
前回からの続きで、StatusBarをやってみた
Qt Designer
![](https://assets.st-note.com/img/1721443680430-d0LkQgYJ5w.png?width=1200)
Windowを作成した状態で、すでにStatusBarはあるのでこれを使う
関数の作成と使用
from PySide2.QtWidgets import QStatusBar
class TestWindow(QMainWindow):
def __init__(self, parent=qtmax.GetQMaxMainWindow()):
self.statusbar = self.ui.findChild(QStatusBar, 'statusbar')
self.setStatusBar(self.statusbar)
def showMessage(self, message):
self.statusbar.showMessage(message)
前回のTestWindowクラスに上記を追加するだけ
TeaPotを作成すると、ウィンドウ下側に"Create TeaPot"と表示される
![](https://assets.st-note.com/img/1721444094040-l3i6YFlq85.png?width=1200)
これだけ
TestWindowクラス
ここで、ちょっとTestWindowクラスの説明をする
class TestWindow(QMainWindow):
def __init__(self, parent=qtmax.GetQMaxMainWindow()):
QMainWindow.__init__(self, parent)
loader = QUiLoader()
ui_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '.\\ui\\ui_HelloWindow.ui')
ui_file = QFile(ui_file_path)
ui_file.open(QFile.ReadOnly)
self.ui = loader.load(ui_file, self)
# Get title of window from ui
title = self.ui.windowTitle()
self.setWindowTitle(title)
# Get size of window from ui
w = self.ui.size().width()
h = self.ui.size().height()
self.resize(w, h)
ui_file.close()
コードのこの部分は、クラスの初期設定に関係する
まず、TestWindowはPySideのQMainWindowを継承
コンストラクタの引数として、parentにqtmax.GetQMaxMainWindow()で3dsMaxのメインウィンドウを取得
QMainWindow.__init__()で継承先のクラスのコンストラクタを実行
その後は、uiファイルの読み込みんで、self.uiとしてインスタンス変数にuiの情報を保持している
後は、そこからオブジェクトを取得して、実際にインスタンス化するTestWindowにそれぞれセットすることで、UIを表示できるようにしている。
self.uiはあくまでもQt Designerで作成したUI情報を持っているだけなので、これを読み込んだだけではUIは表示されない
実際にインスタンス化するのはTestWindowなので、こちらにQt Designerで設定したものを、再設定していく作業が必要