Re: [gtkmm] Entry widget width



Greg Rogers wrote:

Why do I need to set the width to 13 to get it to match the max length
of 18 (16 hex characters, plus '0x')?


I've had the same problem... GtkEntry uses pango_font_metrics_get_approximate_char_width() to calculate the width, and I guess this snippet from the pango source says it all:

  /* This is pretty darn bogus. */
  if (n_avg_widths)
    metrics->approximate_char_width = total_avg_widths / n_avg_widths;
  else
    metrics->approximate_char_width = 10 * PANGO_SCALE;

It's strange that it doesn't get it right for a fixed-width font, though. Perhaps using something like the following code to instead calculate an appropriate pixel width (adapted from gtkaccellabel.c) works better:

  gint width;
  PangoLayout *layout;
  layout = gtk_widget_create_pango_layout(widget, "0x0000000000000000");
  pango_layout_get_pixel_size (layout, &width, NULL);
  set_size_request(width, -1)

--
Christer Palm




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