Toggle button as Indicator only

Toggle button as Indicator only

Post by jfortiz6 » Fri, 05 May 2006 00:17:02

How do I get the look of a radiobutton, but only have the functionality
of an indicator that shows different colors for different states?

Toggle button as Indicator only

Post by Fred Klein » Fri, 05 May 2006 06:40:46

In Motif 2.x, Use a ToggleButton, setting XmNindicatorType as desired.
Showing different COLORS is a bit more difficult, depending on how many
states you have.
You could just set XmNforeground, but that also changes the color of the
text, unless you
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
use a RenderTable to set text colors.


Toggle button as Indicator only

Post by nojun » Fri, 05 May 2006 12:15:28

#include <Xm/ToggleB.h>

static const String color_list[] = {
"Red", "Green", "Blue", "Cyan", "Magenta", "Yellow"

static Pixel pixel_list[XtNumber(color_list)];

static const Cardinal num_colors = XtNumber(color_list);

static void valueChangedCallback(Widget w, XtPointer client_data,
XtPointer call_data)
XtPointer p;
int i;

XtVaGetValues(w, XmNuserData, &p, NULL);
i = ((int) p + 1) % num_colors;
XmNset, XmUNSET,
XmNunselectColor, pixel_list[i],
XmNuserData, (XtPointer) i,

int main(int argc, char **argv)
XtAppContext app;
Widget shell, button;
Display *dpy;
Screen *scr;
Colormap cmap;
XColor color, exact_color;
int i;

shell = XtAppInitialize(&app, "XmTest", NULL, 0, &argc, argv, NULL,
NULL, 0);
dpy = XtDisplay(shell);
scr = XtScreen(shell);
cmap = DefaultColormapOfScreen(scr);
for (i = 0; i < num_colors; i++) {
pixel_list[i] = XAllocNamedColor(dpy, cmap, color_list[i],
&color, &exact_color) ?
color.pixel : WhitePixelOfScreen(scr);
button = XmCreateToggleButton(shell, "button", NULL, 0);
XtAddCallback(button, XmNvalueChangedCallback,
valueChangedCallback, NULL);
XmNunselectColor, pixel_list[0],
XmNindicatorType, XmONE_OF_MANY,
XmNuserData, (XtPointer) 0,

return 0;

I hope it helps.

--- Casantos