Use datatips within App Designer

7 views (last 30 days)
ScottE
ScottE on 30 Jun 2017
Answered: Ayush Singh on 16 Jul 2024
I am creating a GUI with App Designer and I want to add datatips so that the user can move their mouse over a table and see additional information that is not in the table column headers, i.e. units. Is this possible?

Answers (1)

Ayush Singh
Ayush Singh on 16 Jul 2024
Hey ScottE,
Adding custom datatips (tooltips) directly to UITable components for individual cells is not natively supported in the same way as it is for plots. However, you can achieve a similar effect by using uitable properties and callbacks.
Here’s an approach to simulate datatips for a UITable in App Designer by using the CellSelectionCallback and TooltipString properties:
You can follow below steps to acheive the same:
1. Add a UITable to Your App:
Drag a UITable component onto your app from the Component Library.
2. Define Your Data and Units:
Store the information (like units) in a separate structure or cell array.
3. Implement the CellSelectionCallback:
Use the `CellSelectionCallback` to update the tooltip based on the selected cell.
Here’s an example to illustrate how you can implement this:
Here is the complete example:
classdef MyApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
end
properties (Access = private)
Units % Cell array to store units or additional info
end
methods (Access = private)
% Function to initialize the table and units
function initializeTable(app)
% Example data for the table
data = {
'Item1', 10, 20.5;
'Item2', 15, 30.75;
'Item3', 20, 40.25
};
% Set the data to the UITable
app.UITable.Data = data;
% Define the units or additional information
app.Units = {
'Item Name', 'Count (units)', 'Value (USD)'
};
end
% Cell selection callback function
function UITableCellSelection(app, event)
% Get the indices of the selected cell
indices = event.Indices;
if ~isempty(indices)
% Get the column index of the selected cell
colIndex = indices(2);
% Update the tooltip based on the selected column
tooltipText = app.Units{colIndex};
app.UITable.Tooltip = tooltipText;
else
% Clear the tooltip if no cell is selected
app.UITable.Tooltip = '';
end

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!