LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2011, 06:18 AM   #1
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
GtkWidget (label) not showing!


Hi,

I found a bug in my program and I do not understand it. In this testcode a gtklabel "1111" is shown in a gtkbox in a topwindow. When I enter the topwindow a signal is sent and the gtklabel "1111" is destroyed. When I leave a new gtklabel "2222" shall be created and shown but it does not work. If I leave a second time the gtklabel "2222" is shown.

I played around with realizing, mapping, showing but i can not get it to work. Any ideas?

Code:
#include <stdio.h>
#include <stdlib.h>

#include <gtk/gtk.h>

GtkWidget *window;
GtkWidget *box;
GtkWidget *label1;
GtkWidget *label2;

gboolean the_leave(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
    label2 = gtk_label_new(" 2222 ");
    gtk_container_add(GTK_CONTAINER(box), label2);
    gtk_widget_show_now(label2);
    
    gtk_widget_show_all(window);
    return FALSE;
}

gboolean the_enter(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
    if (label1 != NULL)
    {
        gtk_widget_destroy(label1);
        label1 = NULL;
    }
    gtk_widget_show_all(window);
    return FALSE;
}

int main(int argc, char** argv)
{
    gtk_init (&argc, &argv);

    label2 = NULL;

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_set_resize_mode(GTK_CONTAINER(window), GTK_RESIZE_IMMEDIATE);
    gtk_container_set_border_width(GTK_CONTAINER(window), 100);
    g_signal_connect(window, "delete_event", (GCallback)gtk_main_quit, 0);
    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
    gtk_window_stick(GTK_WINDOW(window)); /* on all desktops or not */
    gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
    gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);

    box = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), box);

    label1 = gtk_label_new(" 1111 ");
    gtk_container_add(GTK_CONTAINER(box), label1);

    g_signal_connect(window, "enter-notify-event", G_CALLBACK(the_enter), NULL);
    g_signal_connect(window, "leave-notify-event", G_CALLBACK(the_leave), NULL);
    
    gtk_widget_show_all(window);

    gtk_main ();
    return (EXIT_SUCCESS);
}

Last edited by kalleanka; 08-25-2011 at 06:21 AM.
 
Old 08-25-2011, 07:57 AM   #2
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
It works if i do not use
gtk_container_set_resize_mode(GTK_CONTAINER(window), GTK_RESIZE_IMMEDIATE);.

I would think it should work. Maybe a bug.

Happy Programming
 
  


Reply



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
LABEL=/1 vs LABEL=/ in linux !! shipon_97 Linux - Newbie 1 06-02-2010 08:33 AM
trouble umounting with LABEL=label in fstab JosephS Debian 3 02-01-2010 06:25 AM
deleting gtkwidget pointers nonis Programming 4 10-30-2008 12:06 PM
How to draw the JPEG file into GtkWidget stny Programming 3 04-26-2006 08:14 PM
GtkWidget color prabhakar_kushwaha Programming 1 10-22-2005 01:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 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
Open Source Consulting | Domain Registration