在此功能(应用程序设计器)中,我使用鼠标左键选择删除表格中的一行,如何使用右键或其他键+鼠标组合而不是左键进行选择?
代码:
% Cell selection callback: infoTable
function infoTableCellSelection(app, event)
indices = event.Indices;
data = app.infoTable.Data;
row = indices(:,1);
figSelect = uifigure;
figSelect.SelectionType ='alt';
selection = uiconfirm(figSelect,'Delete row?','Confirm Close',...
'Icon','question');
disp(selection);
disp(figSelect.SelectionType);
switch selection
case 'OK'
app.infoTable.Data(row,:) = [];
close(figSelect);
case 'Cancel'
close(figSelect);
return
end
后面的代码:
function createComponents(app)
...
app.infoTable.CellSelectionCallback = createCallbackFcn(app, @infoTableCellSelection, true);
最佳答案
可以通过父 uifigure
检测到在选择 uitable 时按下的任何修饰键(即 shift、control)(我将其称为 app.figMain
).修饰符通过未记录的命令 modifiers = get(app.figMain,'CurrentModifier')
在元胞数组中返回。您可以使用 if
语句,该语句仅在 modifiers
中未列出任何按键时运行。换句话说,表格选择回调仅针对左键单击运行,而不会针对 shift-click、ctrl-click 等运行。
在给定的代码中实现:
function infoTableCellSelection(app, event)
modifiers = get(app.figMain,'CurrentModifier');
if isempty(modifiers) % Check that shift-key, ctrl-key, etc. is not pressed
indices = event.Indices;
data = app.infoTable.Data;
row = indices(:,1);
figSelect = uifigure;
selection = uiconfirm(figSelect,'Delete row?','Confirm Close',...
'Icon','question');
disp(selection);
disp(figSelect.SelectionType);
switch selection
case 'OK'
app.infoTable.Data(row,:) = [];
close(figSelect);
case 'Cancel'
close(figSelect);
return
end
end
end
MATLAB Undocumented 描述了 CurrentModifier
命令:CurrentModifier
https://stackoverflow.com/questions/62473633/
相关文章:
ios - VoiceOver 在 UITableView 中滚动,其中单元格和 subview 都
react-native - 在通过深度链接导航到特定路线导航时 React Native。goBa
visual-studio-code - VScode 中的 vim 仿真扩展导致问题
flutter - 在 Flutter 应用程序中从 pubspec for web 获取版本
javascript - 为什么字符串中的等号会抛出意外的标记错误?
python - Librosa 无法从 BytesIO 加载
c# - 尽管已添加到我的项目中但无法使用 Bootstrap