Re: Problems with Gtk::Table





On Tue, 9 Aug 2005, Erik Ohrnberger wrote:

Isn't it that once a widget is attached to the table, you can't go and
just attach it again?  I believe that there might be a method to deatch
the widget, but I've not needed or looked for it.

Actually it's possible to use "remove" (inherited from Widget).
And also I had to add "show_all" at the end to have new widgets appear.
(maybe they would show up on forced update such as a resize anyway...)

//Marcus


Hope this help,
   Erik.

On Tue, August 9, 2005 12:49, Marcus Lundblad said:
Hello.

I have a problem with a class derived from Gtk::Table
In this class I have a method "rearrange" that is called when changing
the layout of this table:

void
desks_table::rearrange()
{
   int num_cols = (unsigned int)(std::ceil(double(double(num_desks())/
 						 double(num_rows()))));
   std::cerr << "resize( " << num_rows() << ", " << num_cols << std::endl;
   TableList& tl = children();
   std::cerr << "children size = " << tl.size() << std::endl;
   int child_size = tl.size();
   tl.clear();

   resize(num_rows(), num_cols);
   int desk = 0;
   for(int i = 0 ; i < num_rows() ; i++) {
     for(int j = 0 ; j < num_cols && desk < num_desks() ; j++) {
       std::cerr << "attaching desk " << desk << std::endl;
       attach(*(desk_widgets[desk]), j, j+1, i, i+1);
       desk++;
     }
   }
}

The "desk_widgets" is (currently) std::vector<Gtk::Label>, but will be a
derived class later on, this vector is maintained outside of this method
(the idea is that this should be usable both when changing number of
subwidgets and rearraging, columns and rows).
The first time this is called (as a consequence of the constructor), there
is no widgets attached and there's 4 widgets allocated in the vector.

The follwing gets printed:

------------------------------------------------------

resize( 1, 4
children size = 0
attaching desk 0
attaching desk 1
attaching desk 2
attaching desk 3

------------------------------------------------------

and the widgets appear in the table as expected.

The second time the vector has one more element.
the printout now:

-------------------------------------------------------------------------

resize( 1, 5
children size = 4

(gov:7206): Gtk-CRITICAL **: gtk_container_remove: assertion
`GTK_IS_WIDGET (widget)' failed

(gov:7206): Gtk-CRITICAL **: gtk_container_remove: assertion
`GTK_IS_WIDGET (widget)' failed

(gov:7206): Gtk-CRITICAL **: gtk_container_remove: assertion
`GTK_IS_WIDGET (widget)' failed

(gov:7206): Gtk-CRITICAL **: gtk_container_remove: assertion
`GTK_IS_WIDGET (widget)' failed
attaching desk 0

(gov:7206): Gtk-CRITICAL **: gtk_table_attach: assertion `child->parent ==
NULL' failed
attaching desk 1

(gov:7206): Gtk-CRITICAL **: gtk_table_attach: assertion `child->parent ==
NULL' failed
attaching desk 2

(gov:7206): Gtk-CRITICAL **: gtk_table_attach: assertion `child->parent ==
NULL' failed
attaching desk 3

(gov:7206): Gtk-CRITICAL **: gtk_table_attach: assertion `child->parent ==
NULL' failed
attaching desk 4

--------------------------------------------------------------------------

When calling tl.clear() on the children something goes wrong,
(the exact same thing happens using tl.erase(tl.begin(),tl.end()) )
the table is resized, but the new slot is empty (even though the last
attach, on the slot that's new didn't seem to fail.

What am I doing wrong? (I've read the documentation and check sample
codes, but can't seem to get it right).

//Marcus

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]