GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 2:12 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Label Alignment
PostPosted: Mon Aug 13, 2012 6:04 am 
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 64
Hello Everyone
I have written a code which uses a XML with a lable.
When designing the XML in glade the text with the label appears correctly centered withing the label.
But when the XML is loaded into the program the text appear offset to the LEFT of the label.
Also changing the text in the label has the new text offset to the LEFT. Why does this happen and how can I get around it?
The code I have used is below and the XML file is also below(For some reason i cannot attache any files, it keeps telling me that all the extensions that I have attached are not allowed!!!).

#include <gtk/gtk.h>

//gcc -Wall -g fixed-xml.c -o fixed-xml -export-dynamic `pkg-config --cflags --libs gtk+-2.0`
GtkWidget *window, *fixed, *label, * button;

static void new_text (GtkWidget * button, gint data)
   gtk_label_set_markup(GTK_LABEL(label), "<span font_desc='11'><b> Bonkey! how are you today.\nThe day is bright and sunny and the morning is funny.\nAnd now I have spotted a bunny!</b></span>");

int main (int argc, char *argv[])
   GtkBuilder * builder;
  gtk_init (&argc, &argv);
   builder = gtk_builder_new ();
   gtk_builder_add_from_file (builder, "fixed-xml.xml", NULL);
  window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
  gtk_window_set_title (GTK_WINDOW (window), "Fixed");
  gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (gtk_main_quit), NULL);
  fixed = GTK_WIDGET (gtk_builder_get_object (builder,"fixed"));

   label =  GTK_WIDGET (gtk_builder_get_object (builder,"label"));
   button =  GTK_WIDGET (gtk_builder_get_object (builder,"button1"));
  g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (new_text), NULL);
   g_object_unref (G_OBJECT (builder));
  gtk_widget_show_all (window);
  gtk_main ();
  return 0;

Please name the file as "fixed-xml.xml"
<?xml version="1.0" encoding="UTF-8"?>
  <!-- interface-requires gtk+ 2.12 -->
  <object class="GtkWindow" id="window">
    <property name="can_focus">False</property>
    <property name="default_width">400</property>
    <property name="default_height">200</property>
    <signal name="destroy" handler="on_WindowLogout_destroy" swapped="no"/>
      <object class="GtkFixed" id="fixed">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
          <object class="GtkLabel" id="label">
            <property name="width_request">800</property>
            <property name="height_request">100</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">&lt;span font_desc='11'&gt;&lt;b&gt; Hello how are you today.
The day is bright and sunny and the morning is funny.
And now I have spotted a bunny!&lt;/b&gt;&lt;/span&gt;</property>
            <property name="use_markup">True</property>
            <property name="justify">center</property>
            <property name="wrap">True</property>
          <object class="GtkButton" id="button1">
            <property name="label" translatable="yes">Put new text
            <property name="use_action_appearance">False</property>
            <property name="width_request">800</property>
            <property name="height_request">41</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="use_action_appearance">False</property>
            <property name="y">120</property>

Hello, העלו, Здравствулте!

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group