Re: Bug? in OptionMenu, when changing text of selected label



Bill McGrory wrote:
> 
> >>>>> " " == Damon Chaplin <damon@helixcode.com> writes:
> 
>      > The GtkOptionMenu uses a trick of moving the selected widget from the
>      > menu into the button that you use to pop up the menu.
> 
>      > So you could try changing the widget inside the option menu button.
> 
> Nope, no cigar. I am doing a set_text directly on the label. If I get
> the label from the menulist, it's the same label as the one that's
> attached to the optionmenubutton (verified through a debug
> session). So that doesn't help.

The problem seems to be that the GtkOptionMenu does not call size_request()
on the widget in the button. Some widgets, like GtkLabel, do not work if
the parent doesn't call size_request() on them. I've hit this problem
before myself. I'm not sure if it should be considered a bug in GtkLabel
or in the parent container.

This works for me:

void change( GtkWidget *widget,
            gpointer   data )
{
  GtkRequisition child_requisition;

  char str[100];
  sprintf(str,"Count%d",count++);
	
  gtk_label_set_text(GTK_LABEL(label),str);

  /* GTK+ bug workaround - get the label to recalculate its layout. */
  gtk_widget_size_request (label, &child_requisition);
	
  g_print ("In Changed\n");
}


There is another problem in GtkOptionMenu which means that with your
code selected item is blank initially.
It will appear if you add the menuitems before setting the
menu in the GtkOptionMenu, like this:

  menu = gtk_menu_new ();
	
  button1 = gtk_menu_item_new_with_label("Button 1" );
  button2 = gtk_menu_item_new_with_label("Button 2" );
  label = GTK_BIN(button1)->child;

  gtk_menu_append (GTK_MENU (menu), button1);
  gtk_menu_append (GTK_MENU (menu), button2);

  gtk_option_menu_set_menu(GTK_OPTION_MENU(option), menu);


Damon






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]