필터 지우기
필터 지우기

appdesigner setting uistyle back to default

조회 수: 19 (최근 30일)
John H.
John H. 2023년 3월 23일
댓글: Earl Davis 2023년 4월 8일
hello all
I have an app in appdesigner with a uitable
I can easily use uistyle to set a cells background color, for example...
s = uistyle('BackgroundColor','blue');
addStyle(app.UITable , s, 'cell', indicies);
My problem is that i cannot fiigure out how to set that cell back to default.
(note, i know of the removestyle command, but that seems to act on the whole table, i just need the cell to be reset to default)
Documentation seems to imply i can do
s = uistyle('BackgroundColor',[]);
addStyle(app.UITable , s, 'cell', indicies);
but that does nothing apparenlty.
Am i missing something?

채택된 답변

Cameron
Cameron 2023년 3월 23일
removeStyle(app.UITable)
  댓글 수: 3
Cameron
Cameron 2023년 3월 23일
My apologies. I forgot to include this bit. removeStyle(comp,ordernum) allows you to remove specific styles. So you can put a second arguement in that dictates which of your styles to remove. For example:
removeStyle(app.UITable,1)
%or
removeStyle(app.UITable,2)
%or whatever the order of your style is
To check this, use
app.UITable.StyleConfigurations
John H.
John H. 2023년 3월 23일
Cameron, thank you for elaborating. Much appreciated.
Since you are listed as staff, I will put my slip into the suggestion box via you.
Its kind of silly that one can create and assign a style based on the cells row column index. But one can apparently only remove that style by figuring out in what order you created the styles. Wouldn't you agree?
I guess what I'm going to have to do is create a structure or something which manages my cells and keeps the cell and styles linked in some capacity, such that I can create and delete them based on cell index.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Earl Davis
Earl Davis 2023년 3월 28일
편집: Earl Davis 2023년 3월 28일
function destyle(~,itm,target,indices)
%Remove the style from any single piece of a stylable thing. For example,
%whack an icon from a single cell. Just a first attempt, could probably be improved on.
%
%itm: any uiThing for which the addStyle command produces a StyleConfiguration property
%target: a feature of the itm (e.g., row, column, cell)
%indices: which one izzat?
%
%
%Usage: app.destyle(app.tblCI,"cell",indices);
oldStyle = itm.StyleConfigurations; %Make new friends, but keep the old.
removeStyle(itm);%Whack all that
for idx = 1:size(oldStyle,1) %Runs fast enough that I didn't even try to vectorize it
%Reimpose all of the styles EXCEPT those matching the target and indices
if (oldStyle.Target(idx) ~= target) || any(oldStyle.TargetIndex{idx} ~= indices)
addStyle(itm,oldStyle.Style(idx),oldStyle.Target(idx),oldStyle.TargetIndex{idx});
end
end
end
  댓글 수: 2
John H.
John H. 2023년 3월 28일
wow, i will give this a shot when im working that code next .
thank you!
Earl Davis
Earl Davis 2023년 4월 8일
I have been working with Matlab more or less continually since about 1991. The single most important lesson I've learned is that like Ogres (and onions, and parfait), Matlab has layers. I peel layers all the time, often by accident (sometimes due to road rash), and never seem to know in advance what I'll find under the next one.
My personal favorite was discovering how to co-simulate Simulink/Stateflow with Excel for an aircraft pneumatic problem and...well, nevermind.
I was peeling something completely different & stumbled across the full syntax for removeStyle, as if for the first time. Naturally, I had to try it.
function destyle(~,itm,target,indices)
idx = 1;
while idx <= size(itm.StyleConfigurations,1)
if (itm.StyleConfigurations.Target(idx) == target) || all(itm.StyleConfigurations.TargetIndex{idx} == indices)
removeStyle(itm,idx);
idx = idx - 1;
end
idx = idx + 1;
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by