Widget problem [GTK RELATED]

This is a discussion on Widget problem [GTK RELATED] within the C Programming forums, part of the General Programming Boards category; Hi, I decided to make new structure of GtkWidget's and also a function which will organise them in my order, ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    10

    Widget problem [GTK RELATED]

    Hi, I decided to make new structure of GtkWidget's and also a function which will organise them in my order, it looks like:

    Structures:

    Code:
    typedef struct{
    	std::string tytul,opis,typ;
    	short int godzina,minuta,p_godzina,p_minuta,dzien,miesiac,rok,ID,ilosc;
    } Wydarzenie;
    
    typedef struct{
    	std::string kawalek_opisu;
    	short int ID;
    	GtkWidget* Labels[5];
    	GtkWidget* Vbox;
    	GtkWidget* Hboxs[2];
    	GtkWidget* Event_Box;
    } NowyWidget;
    Function to create "new" widget:

    Code:
    NowyWidget nowy_widget_init(Wydarzenie wydarzenie)
    {
    	std::string czas;
    	char bufor[3] = {0};
    	NowyWidget widget;
    	widget.Event_Box = gtk_event_box_new();
    	gtk_widget_set_events (widget.Event_Box, GDK_BUTTON_PRESS_MASK);
    	for (int i = 0; i < 2; ++i) widget.Hboxs[i] = gtk_hbox_new(FALSE,0);
    	widget.ID = wydarzenie.ID;
    	widget.kawalek_opisu.assign(wydarzenie.opis,0,20);
    	widget.kawalek_opisu += "...";
    	widget.Labels[0] = gtk_label_new(wydarzenie.tytul.c_str()); // Labels[0] tytul;
    	widget.Labels[1] = gtk_label_new(wydarzenie.typ.c_str()); //Labels [1] typ;
    	widget.Labels[2] = gtk_label_new(widget.kawalek_opisu.c_str());
    
    	itoa(wydarzenie.p_godzina,bufor,10);
    	czas = bufor;
    	czas += ":";
    	itoa(wydarzenie.p_minuta,bufor,10);
    	czas += bufor;
    
    	widget.Labels[3] = gtk_label_new(czas.c_str());
    
    	czas.clear();
    
    	itoa(wydarzenie.godzina,bufor,10);
    	czas = bufor;
    	czas += ":";
    	itoa(wydarzenie.minuta,bufor,10);
    	czas += bufor;
    
    	widget.Labels[4] = gtk_label_new(czas.c_str());
    	widget.ID = wydarzenie.ID;
    	widget.Vbox = gtk_vbox_new(FALSE,0);
    	gtk_container_add(GTK_CONTAINER(widget.Event_Box),widget.Vbox);
    	gtk_box_pack_start(GTK_BOX(widget.Vbox),widget.Hboxs[0],FALSE,FALSE,0);
    	gtk_box_pack_start(GTK_BOX(widget.Hboxs[0]),widget.Labels[0],FALSE,FALSE,0);
    	gtk_box_pack_end(GTK_BOX(widget.Hboxs[0]),widget.Labels[1],FALSE,FALSE,0);
    	gtk_box_pack_start(GTK_BOX(widget.Vbox),widget.Hboxs[1],FALSE,FALSE,0);
    	gtk_box_pack_start(GTK_BOX(widget.Hboxs[1]),widget.Labels[2],FALSE,FALSE,0);
    	gtk_box_pack_start(GTK_BOX(widget.Hboxs[1]),widget.Labels[3],FALSE,FALSE,0);
    	gtk_box_pack_end(GTK_BOX(widget.Hboxs[1]),widget.Labels[4],FALSE,FALSE,0);
    	return widget;
    }
    I also made a vector of this "new" widgets and use it like that in code:

    std::vector<NowyWidget> zbior_widgetow;

    Code:
    Wydarzenie temp;
    	NowyWidget duzo;
    	temp.dzien = 1;
    	temp.godzina  = 1;
    	temp.ID = 1;
    	temp.ilosc  = 1;
    	temp.miesiac = 1;
    	temp.minuta = 1;
    	temp.opis = "test";
    	temp.p_godzina = 1;
    	temp.p_minuta = 1;
    	temp.rok = 1;
    	temp.typ = "TEST";
    	temp.tytul = "TESTING";
    	for (int i = 0; i < 10; ++i) 
    	{
    		memset((void*)&duzo,0,sizeof(NowyWidget));
    		duzo = nowy_widget_init(temp);
    		zbior_widgetow.push_back(duzo);
    	}
    
    for (unsigned i = 0; i < zbior_widgetow.size(); ++i) gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(Okno_przesuw),zbior_widgetow[i].Event_Box);
    And GTK allows me to place only one widget, with the rest I get:

    "gtk_scrolled_window_add_with_viewport : assertion 'GTK_BIN (bin->child)->child == NULL' FAILED, and it palces only the first one widget in window.

    Any help needed
    Last edited by darekg11; 05-09-2011 at 10:39 AM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Mods... this should be moved to C++

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    10
    It's bassicly C , just using std::vector whole GTK is in C so I tihnk it fits here more.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by darekg11 View Post
    It's bassicly C , just using std::vector whole GTK is in C so I tihnk it fits here more.
    Ok... but you're far more likely to get good answers in the other forum.

    How about we let the moderators decide...

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    10
    I think i can get anwsers of better quality here because whole GTK interface is in C and problem probably occours because of some bad deleting widgets or something like that and not even touches vector. Anyway moderators will decide.

    EDIT: I'm such a retard I had to put Vbox first in scrolled window.... Moderators please close/delete topic.
    Last edited by darekg11; 05-09-2011 at 10:49 AM.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,165
    Moderators please close/delete topic.
    Why should they? It is a legit case that may be helpful to others.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Widget tookits
    By Epy in forum Tech Board
    Replies: 0
    Last Post: 05-04-2011, 11:30 AM
  2. Best widget toolkit?
    By TriKri in forum C++ Programming
    Replies: 5
    Last Post: 03-25-2010, 01:10 PM
  3. Latest Topics widget
    By Programmer_P in forum Tech Board
    Replies: 1
    Last Post: 07-24-2009, 09:25 AM
  4. xuni: a Graphical User Interface Widget Toolkit
    By dwks in forum Projects and Job Recruitment
    Replies: 45
    Last Post: 06-04-2008, 02:35 PM
  5. Class related problem
    By Gnoober in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2002, 10:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21