How are tools added to the tool bar

Within the source, I can’t seem to find how tools (such as the bucket, magic wand) are added to the tool bar. I saw that the “new” “file open” “save” and “undo/redo” are added in maintoolbar.cpp. So in other words, were I to write a new tool, how would I add it to the tool bar?

Might be in a similar place, but if not now would I add something like the “Random Mode” button?


Have a look at the files toolmanager.h and toolmanager.cpp

To add a new tool, you will probably extend the class AbstractTool or the AbstractTileTool which you can find in the files abstracttool.h or abstracttiletool.h. You can go through the files stampbrush.h, bucketfilltool.h, etc to understand how exactly to make a tool.

Apart from this, you can also have a look at CommandButton in the commandbutton.h file which is not exactly a tool but a utility added in the main toolbar.

For the Random Mode button in particular, it is added to the main tool bar in the MapEditor constructor. It’s not a location in the UI that I’m particularly happy with, but a better location currently does not exist (I think a better location would be a tool-specific tool bar, but Tiled doesn’t have that yet).

Thank you for the responses!