LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-23-2009, 08:42 AM   #1
deepthi_rapaka
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
Question xalign/justify properties are not working on GtkLabel


Hi,

I have my gtk label is packed like:


-HBox
-Event Box
- HBox
- Gtk Label

I already did a gtk_misc_set_alignment() to left on the label at the time of creation.

Now,at run time time i want to change the alignment of my label based on the xalign/yalign using gtk_misc_set_alignment(), this is not working.
 
Old 12-26-2009, 06:57 PM   #2
joel2001k
Member
 
Registered: Mar 2007
Distribution: GNU/Linux debian unstable main
Posts: 92

Rep: Reputation: 17
a gtk_misc_set_alignment example

I wrote an example for you to demonstrate how I could work. Did you pack the label correctly? Can you tell me if the code below works for you?

Code:
#include <stdlib.h>
#include <gtk/gtk.h>

void buttons_create(GtkHBox *hbox);
void button_up_callback(GtkButton *button, gpointer data);
void button_left_callback(GtkButton *button, gpointer data);
void button_right_callback(GtkButton *button, gpointer data);
void button_down_callback(GtkButton *button, gpointer data);
gboolean delete_event_callback(GtkWidget *widget, GdkEvent *event, GtkWindow *window);

GtkButton **button;
GtkLabel *label;
gboolean up, left;

void
buttons_create(GtkHBox *hbox)
{
  GtkAlignment *alignment;
  GtkTable *table;
  GtkArrow *arrow;

  alignment = (GtkAlignment *) gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
  gtk_box_pack_start((GtkBox *) hbox, (GtkWidget *) alignment, FALSE, FALSE, 0);

  table = (GtkTable *) gtk_table_new(3, 3, TRUE);
  gtk_container_add((GtkContainer *) alignment, (GtkWidget *) table);

  /* create and pack buttons */
  button = (GtkButton **) malloc(4 * sizeof(GtkButton*));

  button[0] = (GtkButton *) gtk_button_new();
  gtk_table_attach_defaults(table,
			    (GtkWidget *) button[0],
			    1, 2,
			    0, 1);

  arrow = (GtkArrow *) gtk_arrow_new(GTK_ARROW_UP,
				     GTK_SHADOW_NONE);
  gtk_container_add((GtkContainer *) button[0], (GtkWidget *) arrow);

  button[1] = (GtkButton *) gtk_button_new();
  gtk_table_attach_defaults(table,
			    (GtkWidget *) button[1],
			    0, 1,
			    1, 2);

  arrow = (GtkArrow *) gtk_arrow_new(GTK_ARROW_LEFT,
				     GTK_SHADOW_NONE);
  gtk_container_add((GtkContainer *) button[1], (GtkWidget *) arrow);

  button[2] = (GtkButton *) gtk_button_new();
  gtk_table_attach_defaults(table,
			    (GtkWidget *) button[2],
			    2, 3,
			    1, 2);

  arrow = (GtkArrow *) gtk_arrow_new(GTK_ARROW_RIGHT,
				     GTK_SHADOW_NONE);
  gtk_container_add((GtkContainer *) button[2], (GtkWidget *) arrow);

  button[3] = (GtkButton *) gtk_button_new();
  gtk_table_attach_defaults(table,
			    (GtkWidget *) button[3],
			    1, 2,
			    2, 3);

  arrow = (GtkArrow *) gtk_arrow_new(GTK_ARROW_DOWN,
				     GTK_SHADOW_NONE);
  gtk_container_add((GtkContainer *) button[3], (GtkWidget *) arrow);

  /* connect buttons */
  g_signal_connect((GObject *) button[0], "clicked\0",
		   G_CALLBACK(button_up_callback), NULL);

  g_signal_connect((GObject *) button[1], "clicked\0",
		   G_CALLBACK(button_left_callback), NULL);

  g_signal_connect((GObject *) button[2], "clicked\0",
		   G_CALLBACK(button_right_callback), NULL);

  g_signal_connect((GObject *) button[3], "clicked\0",
		   G_CALLBACK(button_down_callback), NULL);
}

void
button_up_callback(GtkButton *button, gpointer data)
{
  if(left)
    gtk_misc_set_alignment((GtkMisc *) label, 0.0, 0.0);
  else
    gtk_misc_set_alignment((GtkMisc *) label, 1.0, 0.0);

  up = TRUE;
}

void
button_left_callback(GtkButton *button, gpointer data)
{
  if(up)
    gtk_misc_set_alignment((GtkMisc *) label, 0.0, 0.0);
  else
    gtk_misc_set_alignment((GtkMisc *) label, 0.0, 1.0);

  left = TRUE;
}

void
button_right_callback(GtkButton *button, gpointer data)
{
  if(up)
    gtk_misc_set_alignment((GtkMisc *) label, 1.0, 0.0);
  else
    gtk_misc_set_alignment((GtkMisc *) label, 1.0, 1.0);

  left = FALSE;
}

void
button_down_callback(GtkButton *button, gpointer data)
{
  if(left)
    gtk_misc_set_alignment((GtkMisc *) label, 0.0, 1.0);
  else
    gtk_misc_set_alignment((GtkMisc *) label, 1.0, 1.0);

  up = FALSE;
}

gboolean
delete_event_callback(GtkWidget *widget, GdkEvent *event, GtkWindow *window)
{
  free(button);
  gtk_main_quit();

  return(FALSE);
}

int
main(int argc, char **argv)
{
  GtkWindow *window;
  GtkHBox *hbox;

  gtk_init(&argc, &argv);

  window = (GtkWindow *) gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(window, 600, 400);

  hbox = (GtkHBox *) gtk_hbox_new(FALSE, 0);
  gtk_container_add((GtkContainer *) window, (GtkWidget *) hbox);

  up = TRUE;
  left = TRUE;

  buttons_create(hbox);

  label = (GtkLabel *) gtk_label_new("some text\0");
  gtk_box_pack_start((GtkBox *) hbox, (GtkWidget *) label, TRUE, TRUE, 0);
  gtk_misc_set_alignment((GtkMisc *) label, 0.0, 0.0);

  gtk_widget_show_all((GtkWidget *) window);
  g_signal_connect((GObject *) window, "delete-event\0",
		   G_CALLBACK(delete_event_callback), window);

  gtk_main();

  return(0);
}
 
Old 12-29-2009, 12:03 AM   #3
deepthi_rapaka
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Hi joel,

The example you gave is working , thanks , I packed the label correctly but i was doing a gtk_widget_set_size_requset() on the label to occupy the space inside the container....tats y the alignment thing was not working.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
101st excuse to justify breaks in studying ie. LQers story part 1 sycamorex General 6 11-12-2009 07:31 PM
get GtkLabel from GtkButton joel2001k Programming 2 06-29-2009 07:40 AM
LXer: Time Warner tries again, fails to justify caps and charges LXer Syndicated Linux News 0 04-12-2009 05:00 PM
Want to switch, but can't justify pulling hair over silly things Red Squirrel Linux - Desktop 8 01-06-2009 08:25 AM
fluxbox menu justify moojuece Linux - Software 1 11-05-2003 11:43 AM


All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration