App Designer uitextarea control gives position values not in pixels when window is maximised?

Here is the output. Can this be translated into pixels or any alternatives?
ans =
1.0e+03 *
1.2728 0.7737 0.6092 0.1143

 採用された回答

Ajay Kumar
Ajay Kumar 2019 年 11 月 13 日
編集済み: Ajay Kumar 2019 年 11 月 14 日
When I do this:
fig = uifigure;
txa = uitextarea(fig);
txa.position
I get the Output as 100 100 150 60 which are pixels.

7 件のコメント

That is true but there is some weirdness in MATLAB that it is often there may be other factors that effect it. So, I just tested the code below which does the job, both in normal and maximised. However, the UI for the app I am working is more and there are more controls in that MATLAB may have to consider when doing the "Auto" anchoring of controls, tho the other controls give pixel values which is wierd that it may be only the UITextarea.
The problem is unreproducible, check the zip also tested it in App Designer.
fig = uifigure;
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
Ajay Kumar
Ajay Kumar 2019 年 11 月 14 日
編集済み: Ajay Kumar 2019 年 11 月 14 日
The app is working perfectly fine with me, as you can see when I click Show Positions button, I can see the position of text area(in PIXELS) in Positions text field.
Also, it works when I maximise the window. Replace the Show Positions callback with
app.PositionsEditField.Value = num2str(fix(app.TextArea.Position));
Also, If you want the components position to be fixed even if window is maximised, you can set the AutoResizeChildren to off
for example
fig = uifigure;
fig.AutoResizeChildren = 'off';
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
Bereketab Gulai
Bereketab Gulai 2019 年 11 月 14 日
編集済み: Bereketab Gulai 2019 年 11 月 14 日
Thanks for your time.
Here is what fix() produced for the numbers that were given by the Position property. Which is does not seem useful.
>> c = [1.2728 0.7737 0.6092 0.1143]
c =
1.2728 0.7737 0.6092 0.1143
>> fix(c)
ans =
1 0 0 0
I am looking to keep it so that it resizes the children, but it should not also change the unit I suppose for specific ones. I have tried applying the unit measurement property to pixels just before calling the Position property of uitextarea.
Bereketab Gulai
Bereketab Gulai 2019 年 11 月 14 日
編集済み: Bereketab Gulai 2019 年 11 月 14 日
Apparently the: fix()
fix(app.TextArea.Position)
Did the "fix" so it is now shows pixel values correctly. This problem I supppose is related to the where number editField would show numbers in that representation due too long and this can be resolve by changing "ValueDisplayFormat" property to integer.
FYI:
I came to this conclusion after checking the internal value of the control, using mlapptools, which was intact, only at the higher level was being modified.
I think you are missing out something in c
In the comment above you have considered c as
c = [1.2728 0.7737 0.6092 0.1143]
you are missing to multiply *1.0e+03
which indicates
[1272.8 773.7 609.2 114.3]
which are pixels.
Bereketab Gulai
Bereketab Gulai 2019 年 11 月 14 日
That is correct, they can be restored to correct unit.
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeUse COM Objects in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by