LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GtkCheckButton - how to put label on the other side of the button? (https://www.linuxquestions.org/questions/programming-9/gtkcheckbutton-how-to-put-label-on-the-other-side-of-the-button-719006/)

Su-Shee 04-14-2009 07:24 AM

GtkCheckButton - how to put label on the other side of the button?
 
Due to a very specific style guide for a project I have to adjust Gtk radio and checkbuttons to show their text label on the _left_ side of the button like this:

apple []
pears []
grape []

Gtks default puts the button on the left side and the textlabel on the right.

Did I miss some incredibly simple flag or do I have to derive a custom button from ToggleButton to archieve that? (If so - some illustrating pseudo code would be appreciated..)

I've tried some hack with not showing the default label of a radio/checkbutton and instead putting my own label on the left side - but as both button-types have a clickable area around them where usally the label is set, this is ugly and not really working.

theNbomr 04-14-2009 09:08 AM

I'm no expert on this subject, but I did play around with radio buttons in Glade, and can suggest a work-around. Make the radio button's label an empty string, and pack a separate label adjacent to it, all within a hbox. The relevant code generated by glade:
Code:

  hbox3 = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (hbox3);
  gtk_table_attach (GTK_TABLE (table1), hbox3, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  label1 = gtk_label_new (_("label1"));
  gtk_widget_show (label1);
  gtk_box_pack_start (GTK_BOX (hbox3), label1, TRUE, TRUE, 0);
  gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_RIGHT);

  radiobutton3 = gtk_radio_button_new_with_mnemonic (NULL, "");
  gtk_widget_show (radiobutton3);
  gtk_box_pack_end (GTK_BOX (hbox3), radiobutton3, FALSE, FALSE, 0);
  gtk_radio_button_set_group (GTK_RADIO_BUTTON(radiobutton3),radiobutton3_group);
  radiobutton3_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton3));

Hoping someone comes up with a better solution.
--- rod.

Su-Shee 04-14-2009 09:59 AM

That's what I did...

As mentioned it's not really that nice because of Gtk sets a clickable area around the label. This is very useful, because you don't have to acutally hit the (tiny) button itself but just the label to activate the check/radio button..

Now I have my clickable area still on the right side of my buttons and my label left-sided.

Here's a screenshot of some checkbuttons.

I could add an EventBox or something like this - but at least I'd like to disable the empty click area on the right side.

kike_coello 04-22-2009 07:34 PM

You could change the size of the window, or modify the size of the columns and rows of your widgets. Also, you can set the labels so that they aren't "clickable", lol, i don't know if that's the right word. Anyways, hope that helps.


All times are GMT -5. The time now is 10:21 PM.