Hiding tabs breaks App built with App Designer in Matlab 2021b that works in 2018b
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
chrisw23
el 7 de Sept. de 2022
Editada: chrisw23
el 7 de Sept. de 2022
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.
Respuestas (1)
Manoj Mirge
el 23 de Feb. de 2023
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 comentario
DJ
el 3 de Nov. de 2023
Editada: DJ
el 3 de Nov. de 2023
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.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!