Hiding tabs breaks App built with App Designer in Matlab 2021b that works in 2018b

26 次查看(过去 30 天)
Within my startup function, I have a command to hide tabs when opening an app built with App Designer:
tabs_to_hide.Parent = [];
In 2018b, all of this works fine. In 2021b, it only works for some Tabs. If i try to hide all tabs that I want to hide, the app figure opens, but from there, nothing else is working any more. If I select only tabs that have no children, everything works fine. Thus, the reason for the app to break appears to be that I hide tabs that have sub-tabs themselves.
Moreover, there is no error message but this. If I try to load data into the app using a button after launching it, nothing happens. If I then force the app to stop, matlab always says:" interrupted while evaluating private button pushed fcn". I therefore assume that the app is taking a huge amount of time doing something but I have no idea what and why this is the case since everything works fine in 2018b.
Thank you very much for any help!
  2 个评论
chrisw23
chrisw23 2022-9-7
编辑:chrisw23 2022-9-7
The tabgroup and other uicontrols, have a Visible property that should be used to toggle the visible state. Killing a uicontrol reference the way you did so far is not recommended I think. Use linkprop to set the state of multiple uicontrols. The link object has a Enabled property to switch the behaviour at runtime.
MatMat
MatMat 2022-9-7
编辑:MatMat 2022-9-7
Thank you. Should this be working for individual tabs as well? I can hide the entire TabGroup, but this is not what I would like to achieve. If I try
set(tab_to_hide,'Visible','off')
I receive the following error:
Error using matlab.ui.container.Tab/set
Unrecognized property Visible for class Tab.
And when trying
set(tab_to_hide,'HandleVisibility','off')
I do not receive any error message but the tabs are still not hidden when opening the app.

请先登录,再进行评论。

回答(1 个)

Manoj Mirge
Manoj Mirge 2023-2-23
Hi,
The individual tab components in MATLAB doesn't have ‘Visible’ property, so we cannot hide tab component like tab group component.
I have tried hiding tabs having children tabs using below command in MATLAB 2021b:
tabs_to_hide.Parent=[];
And I was able to hide every tab including the tab having children sub tabs.
Could you please re-try running your app again in MATLAB 2021b?
And if you still face same error then you can try below mentioned approach to disable certain tabs in Matlab app designer:
Note: Using this approach you won't be able to hide the tab but user will not be able to select the disabled tab.
  • You can write SelectionChangedFcn callback for Tab Group in which you want to disable tabs.
  • SelectionChangedFcn callback will get called every time user tries to switch tabs in Tab group.
  • Whenever user wants to switch to disabled tab, program will call SelectionChangedFcn callback , where you can check the newly selected tab and if that tab is disabled then you can change the TabGroup.SelectedTab property to the previous tab.
  • This way you can prevent user from selecting disabled Tab.
Below is the sample code for the same:
% You can have tab to be disabled in your class property.
app.disabledTab=app.tab_to_disable.
% Callback function
function SelectionChangedFcn(app,event)
% Determine which tab was selected by user
selectedTab=app.TabGroup.SelectedTab;
% Checking if selected Tab is the disabled
if(selectedTab==app.disabledTab)
%Assisgn the old Tab to the Tab Group so user will stay on previous tab only.
app.TabGroup.SelectedTab = event.OldValue;
end
%If selectedTab is not disabled then we will not make any change.
end
I found another Matlab Answer thread which addresses the similar issue. You can check that thread here .
Hope this helps.
  1 个评论
DJ
DJ 2023-11-3
编辑:DJ 2023-11-3
This is currently the best solution I have found, although I still don't like it. The issue is that MATLAB still visibly switches to the disabled tab, however briefly, before completing the callback function. It would be much better to have some way to prevent the tab switch from taking place at all.
One solution that works, although not perfectly, is to use a label object with no color or text as a 'mask' and place it over the tab. If the label's Visible property is set to "on", it can't be clicked through and the tab won't be selectable. If the Visible property is set to "off", the tab will then be selectable. The problem with this is that due to the shape of tabs and the way their size changes based on their text, it can be difficult to place the mask properly.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by