Re-using native 3dsMax icons in a PySide UI

I am building a Qt UI in 3dsMax 2018 using PySide2, this ships with Max so is a pretty vanilla setup.

I would like to access some of the existing icon images that Max uses in its UI, but am having trouble accessing them correctly. As an example, lets look at the humble Undo icon.
image

The Autodesk docs tell me that this icon exists, that it’s path is “MainUI” and the icon is “Undo” and it’s available in sizes 24, 30, 36 and 48.
https://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__developer_icon_guide_icon_guide_html
It also tells me that the icons are stored in the “Light.rcc” and “Dark.rcc” files on disc. These are compiled Qt resource files and not text readable like the .qrc files. These files are found here …

C:\Program Files\Autodesk\3ds Max 2018\UI_ln

I can access the icon as expected though Maxscript using the path and icon name.

rollout test_icons “Testing icons” (
bitmap the_icon iconName:“MainUI/Undo”
)
createDialog test_icons

I can also confirm the path of the icon by using the code below and hovering over the toolbar undo button.

CustomControlsOptions.PrintIconPaths = true

Which gives the following output

Path of this control’s QIcon: [C:\Program Files\Autodesk\3ds Max 2018\UI_LN\IconsDark.rcc] MainUI\Undo
IconSize: 24x24 (native) IconState: off
Available Files: Undo_24.png, Undo_30.png, Undo_36.png, Undo_48.png

https://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_AC26099B_60BF_4C99_997B_DF65F8D47DC1_htm

However when in Python I am unable to access the icon as I would expect. As a minimal example running in Max:

from MaxPlus import GetQMaxMainWindow
from PySide2 import QtCore, QtGui, QtWidgets

main_window = GetQMaxMainWindow()
window = QtWidgets.QMainWindow(parent=main_window)
label = QtWidgets.QLabel(window)
undo_button = QtWidgets.QToolButton(window)
icon = QtGui.QIcon(":/MainUI/Undo")
undo_button.setIcon(icon)

layout = QtWidgets.QVBoxLayout(window)
layout.addWidget(undo_button)
window.setLayout(layout)
window.show()

Pretty interesting, never used the rcc files from max but seems like a great way to reuse the given icons.

Based on qt docs
https://doc.qt.io/qt-5/resources.html

it seems like you just forgot to specify the file name in your icon path
icon = QtGui.QIcon(":/MainUI/Undo_36.png")

Ahh seems like I was pretty close! Critically I was not specifying size (the “.png” isn’t needed).

So this is a working example:

from MaxPlus import GetQMaxMainWindow
from PySide2 import QtCore, QtGui, QtWidgets

main_window = GetQMaxMainWindow()
window = QtWidgets.QMainWindow(parent=main_window)
label = QtWidgets.QLabel(window)
undo_button = QtWidgets.QToolButton(window)
icon = QtGui.QIcon(":/MainUI/Undo_20")
undo_button.setIcon(icon)

layout = QtWidgets.QVBoxLayout(window)
layout.addWidget(undo_button)
window.setLayout(layout)
window.show()

Cheers

is there a way i export the png file with its alpha to a path on disk ?

For the most part they are just all on your hard-drive already
eg
C:\Program Files\Autodesk\3ds Max 2021\UI_ln