Use datatips within App Designer

7 次查看(过去 30 天)
ScottE
ScottE 2017-6-30
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?

回答(1 个)

Ayush Singh
Ayush Singh 2024-7-16
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

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by