use multiple fonts in GUI pushbutton string

1 Ansicht (letzte 30 Tage)
Thomas Casey
Thomas Casey am 14 Nov. 2014
Kommentiert: Geoff Hayes am 20 Nov. 2014
Is there a way to use multiple fonts in string fields of pushbuttons and text in a GUI? The syntax that works for axis labels etc. doesn't seem to work using set(...
For example, I try this:
set(handles.pushbutton8,'String','\fontname{Symbol}t \fontname{Times} (sec)')
and my button string ends up being: \fontname{Symbol}t \fontname{Times} (sec)
instead of: τ (sec)
Anyone know what to do here?

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 14 Nov. 2014
Thomas - one of those undocumented (and so unsupported) features of MATLAB is that you can embed HTML code in the String of your pushbutton (and perhaps other controls/widgets) to get the text that you desire. In your case, you seem to want the tau symbol to be followed by (sec). Try the following
set(handles.pushbutton8,'String','<html>&tau (sec)</html>');
When I try this (R2014a on OS X 10.8.5) I do see the Greek letter tau followed by (sec).
  4 Kommentare
Thomas Casey
Thomas Casey am 20 Nov. 2014
Hi Geoff,
This same thing does not appear to apply for text fields in GUIs. I can't even get normal matlab formatting code to work. I am trying to type "smax" with "s" normal and "max" a subscript. Is there a way around this too or am I stuck?
Tom
Geoff Hayes
Geoff Hayes am 20 Nov. 2014
Hi Tom,
It is too bad that the same formatting elsewhere can't be applied for the text field too (but since it isn't a supported option then...). One very messy way to get what you want is to create an invisible axes and then place a text object (not a text control) within that axes. Something like
haxes = axes('Position',[0 0 1 1],'Visible','off');
text(0.5,0.5,'s_{max}','Parent',haxes)
If the above code were added to your GUI OpeningFcn, then the text, smax, would be placed in the middle of the GUI since the axes covers all of the figure. Messy and not good programming, but if really needed, it will do in a pinch.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by