Re: [gtkmm] How to sort the widgets in a box?



>> its O(logN) or worse, but Gtk::Container::reorder_child (Gtk::Widget&,
>> gint pos) might help. pos starts at zero.
>
>Thanks, but I don't see how I can use that function to sort a list of buttons 
>by label on O(N logN).

grab the label from the button (cast its child to a Gtk::Label and
call get_text(). store the string and a pointer/ref to the button in a
vector. sort the vector using a less_than orderable functor based on
the string. then iterate over the vector calling reorder_child.

never tried it, might have some complications, but i think it should
work. pretty basic STL programming, though STL programming is itself
not common enough these days.

--p



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