View Full Version : [Gtkmm] Combo box

December 9th, 2012, 08:21 AM
It seems to me gtk/mm doesn't provide an easy way to add an item, you have to create a mini model/view shebang.
After googling seems to me the Python backend does have an append_text() method.

So, is there a simple way to add items to the Gtk::ComboBox (in C or C++)?

December 9th, 2012, 09:44 AM
As far as I know, there is no simpler way. You do need to create a model, like in the Gtkmm examples. I'd love to be proven wrong though!

December 9th, 2012, 12:39 PM
First of all, the model-view paradigm is used by Qt too and I think it is very useful. Anyway for simply adding new text items you could use Gtk::ComboBoxText (http://developer.gnome.org/gtkmm/unstable/classGtk_1_1ComboBoxText.html)

December 9th, 2012, 03:56 PM
Thanks, that's what I've been looking for, though creating a new class, rather than just adding the simple methods to the combo box, is a bad idea imo, though typical of gtk.

December 9th, 2012, 10:36 PM
Well it is a good design approach. Imagine if you did the necessary actions with a regular Combobox. Sooner or later you would end up subclassing Combobox and wrapping your methods inside this subclass.

Regular Combobox is useful, for when you want to do advanced things, like display images/text/checkboxes (or all of these) in each item entry.

December 10th, 2012, 06:13 AM
Adding a method (or a few of them) to simplify things and having a powerful widget don't exclude each other, example: I've used Java's swing - it has both in one class, very handy.

Another example of them (over)using the silly subclassing solution is H/VButtonBox, H/VBox, etc, one doesn't need to be a genius to realize this is silly, apparently they finally realized this and declared those classes deprecated and recommend using the parent ones instead (ButtonBox, Box, etc).

They have other silly thingies, like instead of using a single method like setVisible(true/false), they created 2 different methods (hide, set_visible), or using in a single var name both camel case and underlines in their tutorial - gosh, one can't find a sillier naming approach of variables.