How do I set the number of visible lines in a Gtk::TextView?

后端 未结 1 1217
旧时难觅i
旧时难觅i 2021-01-25 04:29

I have a Gtk::TextView that I would always like to have two lines of text visible, regardless of the font size. Obviously if more than two lines were entered then the box would

1条回答
  •  伪装坚强ぢ
    2021-01-25 05:08

    This is very difficult. For example, what will you do if two font sizes are mixed in one line?

    One way to do it is to create a Pango layout of one letter and find out its height. This is an untested simplification of some code I wrote in C one time; but it shouldn't be too much trouble to convert it to C++ and GTKmm:

    PangoLayout *cell = gtk_widget_create_pango_layout(textview, "X");
    int line_height;
    pango_layout_get_pixel_extents(cell, NULL, &line_height);
    g_object_unref(cell);
    gtk_widget_set_size_request(textview, -1, line_height);
    

    0 讨论(0)
提交回复
热议问题