Create push tool in toolbar
creates a push tool in the
toolbar of the current figure and returns the
pt = uipushtool
The current figure must be one created with the
figure function. If
the current figure does not have a child toolbar, then MATLAB® creates one in the current figure to serve as the parent. If a figure created
figure function does not exist, then MATLAB creates one and calls the
uitoolbar function to create a
toolbar to serve as the parent.
Push tools behave like push buttons. When you click them, they appear to depress until you release the mouse button.
Create Push Tool in UI Figure Toolbar
Create a UI figure by calling the
uifigure function. Create a
toolbar in the UI figure.
fig = uifigure; tb = uitoolbar(fig);
Add a push tool to the toolbar. The push tool displays the default icon.
pt = uipushtool(tb);
Add an icon to the push tool by setting the
Icon property value
to the image file
pt.Icon = fullfile(matlabroot,'toolbox','matlab','icons','greencircleicon.gif');
Create Push Tool in New Figure Toolbar
Create a figure by calling the
figure function. Add a toolbar
to the figure. It appears below the default figure toolbar.
f = figure; tb = uitoolbar(f);
Create a push tool in the toolbar. Read a new icon from the indexed image file,
matlabicon.gif. Convert the indexed image to an RGB truecolor image
array. Add the icon to the push tool by setting the
CData property to
the truecolor image
pt = uipushtool(tb); [img,map] = imread(fullfile(matlabroot,... 'toolbox','matlab','icons','matlabicon.gif')); ptImage = ind2rgb(img,map); pt.CData = ptImage;
Create Push Tool in Default Figure Toolbar
Modify the default figure toolbar by adding a push tool to it.
Create a figure by calling the
f = figure;
Get a handle to the default toolbar by finding all objects of type
'uitoolbar' that are in the figure.
defaultToolbar = findall(f,'Type','uitoolbar')
defaultToolbar = Toolbar (FigureToolBar) with properties: Children: [0×0 GraphicsPlaceholder]
Create a push tool in the default toolbar. Create a 16-by-16-by-3 array of random
RGB values to be its icon. Add the icon to the push tool by setting the
CData property to this array.
pt = uipushtool(defaultToolbar); ptImage = rand(16,16,3); pt.CData = ptImage;
Create Color Picker Push Tool in UI Figure Toolbar
Create a push tool that opens the
dialog box when you click it. Change the background color of the UI figure to the color
selected from the color picker.
First, create a program file called
the program file:
Create a UI figure.
Create a toolbar in the UI figure.
Create a push tool in the toolbar.
Add an appropriate icon to the push tool by setting the
Iconproperty value to the full file path to
Create a tooltip for the push tool.
ClickedCallbackproperty to a function handle that references a callback function called
Create a callback function called
colorToolClicked. In it, call the
uisetcolorfunction so that a color picker dialog opens when you click the push tool in the toolbar. Set the default color of the color picker to be the color of the UI figure and specify the title of the color picker as
'Select UI Figure Color'. Make the UI figure the current figure so that it displays on top of all other figures.
function colorPickerPushTool fig = uifigure('Position',[350 500 400 300]); tb = uitoolbar(fig); pt = uipushtool(tb); pt.Icon = fullfile(matlabroot,'toolbox','matlab','icons','paintbrush.gif'); pt.Tooltip = 'Change UI Figure Color'; pt.ClickedCallback = @colorToolClicked; function colorToolClicked(src,event) c = uisetcolor(fig,'Select UI Figure Color'); figure(fig) end end
colorPickerPushTool. Click the push tool to open the color
picker. Then, select a color to change the background color of the UI figure.
parent — Parent toolbar
Parent toolbar, specified as a
Toolbar object. Use this property
to specify the parent toolbar when creating a push tool or to move an existing tool to a
different tool bar.
If a parent toolbar is not specified, then MATLAB creates a push tool in the toolbar of the current figure. The current
figure must be one created with the
figure function. If the current
figure does not have a child toolbar, then MATLAB creates one in the current figure to serve as the parent. MATLAB does not create the push tool in the default figure tool bar.
If a figure created with the
figure function does not exist,
then MATLAB creates one and calls the
uitoolbar function to
create a toolbar that serves as the parent.
If you add multiple push tools or toggle tools to a toolbar, they are added left to right, in the order that they are created.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
'Separator','on' sets the separator line mode to
The properties listed here are only a subset. For a complete list, see PushTool Properties.
Icon — Icon source or file
'' (default) | character vector | string scalar |
n-by-3 truecolor image array
Icon source or file, specified as a character vector, string scalar, or an
n-by-3 truecolor image array. If you
specify a character vector or string scalar, it can be an image file name on the
MATLAB path or a full path to an image file. If you plan to share your app with
others, put the image file on the MATLAB path to facilitate app packaging. Supported image formats include JPEG,
PNG, GIF, and SVG.
If you specify an
n-by-3 array, it is
interpreted as a truecolor image array. For more information about truecolor image
arrays, see Image Types.
If the image you specify is larger than 16-by-16 pixels, then the
Icon property scales the image down so that the entire image fits within the tool. If the image you specify is smaller than 16-by-16 pixels, it is not scaled up to fit the available space.
Icon property is supported only in App Designer and
uifigure-based apps. If the
CData properties are both set, then the
CData property is ignored.
'icon.png' specifies an image file on the MATLAB path.
'C:\Documents\icon.png' specifies a full path to an image file.
Toolbarobjects (and their child
ToggleToolobjects) do not appear in figures whose
WindowStyleproperty is set to
'modal'. If a figure containing a toolbar child has its
'modal', the toolbar child still exists in the
Childrenproperty of the figure. However, the toolbar does not appear while
WindowStyleis set to
UIControlpush buttons, push tools do not set the figure
'open'on the second click.
Version HistoryIntroduced before R2006a
R2020b: Specify custom icons
In apps created in App Designer and using the
uifigure function, to
add a custom icon to a push tool, set the
Icon property. You can
Icon property as an image file or an
n-by-3 truecolor array.
Icon property is recommended over the