Complete unexpected GUI-elements behavior
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Part of quite a large code base, so no code example.... Here's what happens:
- I have a GUI with tabs, panels therein and several vertically stacked elements in each panel. All manually coded.
- In a panel I have a checkbox which determines the visible elements: some may remain visible, others not.
- When triggering the checkbox callback, I determine which elements remain visible in the panel, calculate their total height, set the panel to the required height and then reposition all the visible elements in that panel.
Now the unexpected happens:
- Situation A: Very often, the resulting layout is wrong, all the elements in the panel are placed far too high although the panel height is OK.
- Situation B: If I then force a layout redraw by resizing the window a little bit horizontally (this forces all above calculations to be done again) the layout suddenly appears correct.
- When going from situation A to B I do not see the size of the panel change (correct...). But visually the vertical positions of the elements in the panel do change although the read-back positions via each element handle remain exactly the same for A and B (so it's not that my code has incorrect calculations). That's not right...
Conclusion: it seems to depend on some unknown internal uncertainties how Matlab deals with the GUI element positions that I provide. For window resizing I already implemented a timer delay to have the window redrawn 0.5 seconds after the last resize-callback (plus an additional pause after resizing the tabs to fit them in the window...) to prevent the layout being messed up completely, but things seems very unreliable.
Is an explanation known for the above behavior, and possibly a work-around to have things more reliable?
Because the application was build so users can quite simple add GUI elements with a few lines of code, it is no option to make things completely in AppDesigner or using some external toolbox.
6 commentaires
Rik
le 22 Août 2023
Also, have you checked whether the result is correct if you only call your layout function after calling drawnow? What happens if you omit the first call and only leave the second?
If our suggestion doesn't solve the problem, you might need to try to construct a minimal failing example. Otherwise you'll have to share the entire function for us to have a chance at reproduce this issue.
Jeroen Boschma
le 22 Août 2023
Modifié(e) : Jeroen Boschma
le 22 Août 2023
Réponses (1)
Image Analyst
le 22 Août 2023
Maybe try to build it from scratch using App Designer instead of GUIDE.
2 commentaires
Rik
le 22 Août 2023
Just adding to this: in this thread I present a (thinly veiled) argument to write a GUI from the ground up in code. I still stand behind that advice.
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!