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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
12-23-2009, 08:42 AM
|
#1
|
LQ Newbie
Registered: May 2009
Posts: 4
Rep:
|
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.
|
|
|
12-26-2009, 06:57 PM
|
#2
|
Member
Registered: Mar 2007
Distribution: GNU/Linux debian unstable main
Posts: 95
Rep:
|
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);
}
|
|
|
12-29-2009, 12:03 AM
|
#3
|
LQ Newbie
Registered: May 2009
Posts: 4
Original Poster
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 03:30 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|