如何取消选择适当的单元格/如何禁用单元格选择突出显示? [英] How to deselect cells in uitable / how to disable cell selection highlighting?

查看:365
本文介绍了如何取消选择适当的单元格/如何禁用单元格选择突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下 uitable





实际上每一行都是独立的合适 ,所以除了标题外,所示的图中包含5个。为什么我这样做是我的最后一个问题的问题,导致显示的表。完整的可执行代码,您可以在此处(或以下最小示例)的答案中找到。使用一般GUI的解决方案也在那里,但它会使代码太多,实际上它似乎是一种错误。



可以看到每次我跳到下一行,因此到另一个适合,最后一个选择保持突出显示,看起来愚蠢,虽然它与功能没有关系。



是uitables的'SelectionHighlight'属性,听起来像一个解决方案,但它不改变任何东西。我使用它如下:

  set(src,'SelectionHighlight','off')%其中src是当前uitable 

在各个地方:'CellSelectionCallback' / code>,在'CellEditCallback'结尾处并作为全局属性。但每次最后一个单元格仍然选择。其实我不需要选择。



如何禁用所有我的合适的整个选择或选择突出显示属性?



如何使用此属性,它是否有效果?





显然,此问题也会出现在其他情况下






我创建了一个最小可执行示例,可以在每一行中选择1到3之间的数字。

  function minimalTable 

%基本属性
line_height = 21.32;
table_height = 3 * line_height;
lh = line_height / table_height;

h = figure('Position',[200 100 202 table_height],'numbertitle','off','MenuBar','none');

%addrow(figurehandle,行数,百分比lineheight)
%每个函数调用创建一个新行,后来动态
addRow(h,1,lh);
addRow(h,2,lh);
addRow(h,3,lh);
end

function modifySelection(src,〜)
set(src,'SelectionHighlight','off')
waitfor(src)
end

function [th] = addRow(fh,k,lhp)
selector = {'1'; '2'; '3'};
defaultData = {'select number ...'};
columnformat = {{selector {:}}};
columneditable = true;

th =合适的(fh,'Units','normalized','Position',[0 1-k * lhp 1 lhp],...
' ...
'ColumnName',[],...
'ColumnWidth',{200},...
'ColumnEditable',columneditable,...
' ColumnFormat',columnformat,...
'RowName',[],...
'SelectionHighlight','off',...
'CellEditCallback',@ modifySelection);
end

会导致:



解决方案

经过一些更深入的研究,我发现Matlab支持提供了以下解决方案:

 %覆盖数据使用哑元并恢复旧数据,强制取消选择
function modifySelection(src,〜)
...
temp = get(src,'Data')
set (src,'Data',{'dummy'});
set(src,'Data',temp);

end

最后选择的单元格周围的虚线仍然是!
但是我发现一个解决方案解决了这一点,这也使第一部分不必要。

  function modifySelection(src,evt)
...
fh = get(src,'parent'); %get parent figure handle
copyobj(src,fh); %copy适合父图
delete(src); %删除当前uitable

end

这会导致所需的行为: / p>

>



第二个解决方案的缺点:它滞后一点(可能只是在慢的机器上),因为创建了一个新对象。


I created the following uitable:

actually every single row is an indpendent uitable, so the figure shown contains 5 uitables besides the header. Why I'm doing that was the issue of my last question, resulting in the shown table. Fully executable code you can find in the answer here (or a minimal example below). Solutions using a general GUI are also there, but it would blow up the code too much, and actually it just seems to be a kind of bug.

It can be seen that everytime I jump to the next row, therefore to another uitable, the last selection remains highlighted, which looks stupid, though it doesn't matter for the functionality.

There is the 'SelectionHighlight' property for uitables, sounds like a solution, but it is not changing anything. I used it as following:

set(src,'SelectionHighlight','off')  %where src is the handle of the current uitable

at various places: at the end of a 'CellSelectionCallback', at the end of a 'CellEditCallback' and as global property. But everytime the last cell remains selected. Actually I don't need selection at all.

How can I disable the whole selection or selection highlighting property for all my uitables?

How do I have to use this property, that it has an effect?

Alternatively: how can I change the "highlighting" color (and therefore text-color) so the highlighting is just not visible anymore?

Apparently this issue appears also in other contexts.


I created a minimum executable example, where one can select a number between 1 and 3 in every row.

function minimalTable 

%basic properties
line_height = 21.32;
table_height = 3*line_height;
lh = line_height/table_height;

h = figure('Position',[200 100 202 table_height],'numbertitle','off','MenuBar','none');

% addrow(figurehandle,number of row, percentage lineheight)
% every function call creates a new row, later dynamically
addRow(h,1,lh);
addRow(h,2,lh);
addRow(h,3,lh);
end

function modifySelection(src,~)
set(src,'SelectionHighlight','off')
waitfor(src)
end

function [th] = addRow(fh,k,lhp)
selector = { '1'; '2' ; '3' };
defaultData  =  {'select number...'};
columnformat =  {  {selector{:}}   };
columneditable =  true;

th = uitable(fh,'Units','normalized','Position',[0 1-k*lhp 1 lhp],...
              'Data', defaultData,... 
              'ColumnName', [],...
              'ColumnWidth', {200},...
              'ColumnEditable', columneditable,...
              'ColumnFormat', columnformat,...  
              'RowName',[],...
              'SelectionHighlight','off',...
              'CellEditCallback',@modifySelection);
end

results in:

解决方案

After some deeper research I found out, that the Matlab Support comes out with the following solution:

%overwrite data with a dummy and restore the old data afterwards, to force deselection
function modifySelection(src,~)
 ...
temp = get(src,'Data')
set(src,'Data',{ 'dummy' });
set(src,'Data', temp );

end

Doing this the blue highlighting is gone, BUT the dotted line around the last selected cell remains! But I found a solution resolving this, which also makes the first part dispensable.

function modifySelection(src,evt)
 ...
fh = get(src,'parent');    % get parent figure handle
copyobj(src,fh);           % copy uitable to parent figure
delete(src);               % delete current uitable

end

Which results in the desired behaviour:

Drawback of the second solution: it lags a little (probably just on slow machines), because of the creation of a new object.

这篇关于如何取消选择适当的单元格/如何禁用单元格选择突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆