Complete unexpected GUI-elements behavior
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Rik
el 22 de Ag. de 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
el 22 de Ag. de 2023
Editada: Jeroen Boschma
el 22 de Ag. de 2023
Respuestas (1)
Image Analyst
el 22 de Ag. de 2023
Maybe try to build it from scratch using App Designer instead of GUIDE.
2 comentarios
Rik
el 22 de Ag. de 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.
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!