A toolbar icon with a single action¶
snippets/toolbar/createToolbar.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# This example shows how to add a custom icon to the VRED Toolbar.
4# It creates a toolbar with a single action that prints a message to the console when clicked.
5# The toolbar is also added as a toggle to the View->Toolbars menu.
6
7from PySide6 import QtGui, QtWidgets
8import datetime, os
9
10def my_tool_action():
11 print(f"My Tool: {datetime.datetime.now()}.")
12
13exampleFolder = os.path.join(os.getenv('VRED_ROOT'), "examples", "snippets", "toolbar")
14iconPath = os.path.join(exampleFolder, "my_tool_icon.png")
15
16my_action = QtGui.QAction(QIcon(iconPath), 'My Tool')
17my_action.setToolTip('My Tool\n\nClick to activate.')
18my_action.triggered.connect(my_tool_action)
19
20my_toolbar = QtWidgets.QToolBar('my_toolbar')
21my_toolbar.setToolButtonStyle(QtGui.Qt.ToolButtonTextUnderIcon)
22my_toolbar.addAction(my_action)
23vrGUIService.addMainWindowToolBar(my_toolbar)