Version:

Use the breadcrumbs component to enable users to track their position along a hierarchical path. Breadcrumbs include a path from the home page to the user’s current location. The points in the breadcrumbs refer to a directory or node. Users can easily move positions in the path by selecting one of the breadcrumbs.

For an example of the “breadcrumb” concept, see the Anim Graph navigation in the O3DE Animation Editor.

In an Anim Graph breadcrumb, the graph’s name is displayed as the top level of navigation. Each node that you open appears as a clickable hyperlink.

## Anatomy of the breadcrumbs widget

Breadcrumbs have several customization options. The standard, horizontal layout includes the following features:

(Optional) Enable users to navigate backwards and forwards in their history of breadcrumb paths selections. For example, if you browse to, or choose, a new path in the list, then choose the back button, you will navigate back to the previous breadcrumb position.

Shows the full path from root to tail. Users can select any point in the path to set a new path. Previously selected paths are automatically added to the navigational history.

3. Browse button

(Optional) Technically not part of the breadcrumb. The browse button is often useful because it enables a user to select a completely new path, instead of choosing a different point in the current path. You push the new path to your breadcrumbs widget in your browse button handler code.

If the entire breadcrumb path cannot fit in the allotted space, the points on the path that don’t fit are stacked in a dropdown menu. Users can select these points from the truncation menu.

The simplest breadcrumb example includes the breadcrumbs widget and an optional, initial path. Your code can react to path changes by connecting to the pathChanged signal. Alternatively, you can call pushPath to set the breadcrumb state to match the current state of your project.

When passing a path QString into pushPath, use either forward slash (’/’) or backward slash (’\\’) as a path separator.

### Example

#include <AzQtComponents/Components/Widgets/BreadCrumbs.h>

// Create a new breadcrumbs widget.

// (Optional) Set the initial path.
QString initialPath = "C:/Documents/SubDirectory1/Subdirectory2/SubDirectory3";

// Add the widget to a previously defined QHBoxLayout.

// Listen for path changes.
// Handle path change as needed by your project.
});



In some scenarios, it’s useful for users to be able to navigate back and forth in their navigation history. In addition, you might want to offer a browse button to select a new path.

In the following example, createBackForwardToolBar provides the forward and backward navigation arrows, and a NavigationButton::Browse from AzQtComponents provides a file browser button.

### Example

#include <AzQtComponents/Components/Widgets/BreadCrumbs.h>
#include <QFileDialog>

// Create a new breadcrumbs widget.

// (Optional) Set the initial path.
QString initialPath = "C:/Documents/SubDirectory1/Subdirectory2/SubDirectory3";

// Create the browse button widget.

// Add the widgets to a previously defined QHBoxLayout.

// Update the breadcrumb path from the output of the browse button.
QString newPath = QFileDialog::getExistingDirectory(breadCrumbs, "Select a new path");
if (!newPath.isEmpty())
{
}
});

// Listen for path changes.