GUI freezes after deleting a Tab

1 次查看(过去 30 天)
I've got 6 Tabs in GUI, but one is hidden in the startup fcn. Hidden tab called "Hybrid" is used when user wants to change the engine from Solid one to Hybrid - if so, the Solid one is hidden and the Hybrid appears.
Problem description: I'm using the Browse button (e.g. in Solid tab) right when I start the GUI, and it works - file is imported to GUI, and the Label shows the title of the file. But when I change from Solid to Hybrid and then from Hybrid to Solid again, this button does not work - browse pop up is shown, I choose the file, but then there's no title in the Label, the whole app designer does not respond (+ there is an error sound wherever I click with my mouse, but no errors in the command window).
To hide tabs I've used one of the solutions in Matlab Answer which was to add 2 lines in startupfcn:
app.tg = matlab.ui.container.TabGroup;
app.TabGroup.Children(2).Parent = app.tg;
app.iteration=1;
User can switch between the tabs using both:
1) 2 buttons, "SolidToHybrid", "HybridToSolid" - and their callback:
app.tg.Children(1).Parent = app.TabGroup;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(2).Parent = app.tg;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
2) 2 Switches with the same callback:
if mod(app.iteration, 2) == 0
value = app.Switch.Value;
else
value = app.Switch_2.Value;
end
app.iteration=app.iteration+1;
if strcmp(value,'Hybrid')
app.Switch.Value="Hybrid";
app.tg.Children(1).Parent = app.TabGroup;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(2).Parent = app.tg;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
else
app.Switch_2.Value="Solid";
app.tg.Children(1).Parent = app.TabGroup;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(3).Parent = app.tg;
app.TabGroup.Children(2).Parent = app.tg;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
app.tg.Children(1).Parent = app.TabGroup;
end
this "deletes" all tabs that are to the right and adding the chosen one + the deleted rest in the correct order.
The order of tabs: "First", "Solid", ("Hybrid"), "Fourth", "Fifth", "Sixth"
I've chosen 2 options to eliminate e.g. infinite loops connected with switch (I thought it could be a problem), but it seems like there's a different problem since in both cases "Browsing files" does not work.
Edit: Maybe there's a different, easier way to hide Tabs but with the similar outcome - always only one is visible.
  2 个评论
Neha
Neha 2023-11-14
Hi Mateusz,
I understand that you are facing an issue while hiding tabs in App Designer. You can consider disabling a tab instead of hiding it. To implement this, you can try adding a panel inside the tab which has an "Enable" property to toggle the user interactivity. You can refer to the following documentation link for more information:
Hope this helps!
Mateusz Zagórski
Mateusz Zagórski 2023-11-18
Hi, Neha
We considered disabling the panel but we also thought that making Tabs disappear (meaning that will make "one visible and the other invisible") is way fancier than having the whole tab disabled.
Maybe there's also a way of blocking the access to the Tab (when user clicks it there's a popup that the tab is blocked because of the Switch value).
If nothing helps, I guess we will apply Enable property..

请先登录,再进行评论。

回答(1 个)

Rushikesh
Rushikesh 2024-10-4
I see that you are attempting to switch between two tabs, 'Solid' and 'Hybrid', and wish to toggle their visibility when the switch is activated. Instead of moving the tabs around, you can efficiently manage their visibility by utilizing the "Visible" property of each tab. This can be seamlessly achieved using two switch buttons, as outlined in your initial approach.
For instance:
%Initially set 'hybrid' tab 'visibility' as 'off' in startupFcn.
function SwitchToHybridButtonPushed(app, event)
% Hide Solid tab and show Hybrid tab
app.SolidTab.Visible = 'off';
app.HybridTab.Visible = 'on';
end
function SwitchToSolidButtonPushed(app, event)
% Hide Hybrid tab and show Solid tab
app.HybridTab.Visible = 'off';
app.SolidTab.Visible = 'on';
end

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by