Align a GtkLabel relative to a GtkDrawingArea
I have a GtkLabel and a GtkDrawingArea within a VBox, I want to center the label relative to a X-coordinate of the GtkDrawingArea (which is below of the label in the VBox), how can I tell GTK to center that label relative to that "anchor" point ? This point should b开发者_C百科e the center of the label.
Since your GtkLabel and GtlDrawingArea are inside a GtkVBox, then their position are relative to each other. The following should set the alignment of the label to the center:
gtk_misc_set_alignment(GTK_MISC(label), 0.5F /*X*/, 0.5F /*Y*/);
If you don't want to center the text of the GtkLabel, then you might use GtkAlignment widget:
GtkWidget* helper;
helper = gtk_alignment_new(0.5F /*X*/, 0.5F /*Y*/, 0.0F, 0.0F);
gtk_container_add(GTK_CONTAINER(helper), label);
gtk_box_pack_start_defaults(GTK_BOX(vbox), helper);
You can realign it again by calling gtk_alignment_set
function.
I solved my problem by using gtk_alignment_new
in order to create a centered alignment and then I used gtk_alignment_set_padding
to fill the right padding with the amount of padding needed to align with an arbitrary x-axis value. Thanks for the answers !
精彩评论