I got to a point where I'm adding entries of a custom-made model to a Gtk::ComboBox. But changing the text-based elements to pixbuf elements causes a runtime-warning from Glib-GObject.
Here's the code. I made it as simple and easy to read as possible...
The header:
Code:
#ifndef _TESTING_H_
#define _TESTING_H_
#include <string>
#include <gtkmm.h>
class Testing
{
public:
Testing (Gtk::ComboBox* pComboBox);
~Testing ();
void add_item (Glib::RefPtr<Gdk::Pixbuf>);
//void add_item (std::string);
private:
struct ModelColumns : public Gtk::TreeModel::ColumnRecord
{
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > pixbuf;
//Gtk::TreeModelColumn<std::string> text;
ModelColumns ()
{
add (pixbuf);
//add (text);
}
};
Gtk::ComboBox* m_pComboBox;
const ModelColumns m_columns;
Glib::RefPtr<Gtk::ListStore> m_refListStore;
};
#endif /*_TESTING_H_*/
Implementation:
Code:
#include "testing.h"
Testing::Testing (Gtk::ComboBox* pComboBox)
{
m_pComboBox = pComboBox;
m_refListStore = Gtk::ListStore::create (m_columns);
m_pComboBox->set_model (m_refListStore);
}
Testing::~Testing ()
{
}
void Testing::add_item (Glib::RefPtr<Gdk::Pixbuf> pixbuf)
//void Testing::add_item (std::string text)
{
Gtk::TreeRow entry = *(m_refListStore->append ());
entry[m_columns.pixbuf] = pixbuf;
//entry[m_columns.text] = text;
}
Here is the code from main.cpp where I use that class Testing:
Code:
m_pDashStyleListStore = new Testing (pDashStyleComboBox);
Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create_from_file ("dashoff.png");
m_pDashStyleListStore->add_item (pixbuf);
//m_pDashStyleListStore->add_item ("DashOff");
pixbuf = Gdk::Pixbuf::create_from_file ("dotted.png");
m_pDashStyleListStore->add_item (pixbuf);
//m_pDashStyleListStore->add_item ("Dotted");
pixbuf = Gdk::Pixbuf::create_from_file ("dashed.png");
m_pDashStyleListStore->add_item (pixbuf);
//m_pDashStyleListStore->add_item ("Dashed");
pixbuf = Gdk::Pixbuf::create_from_file ("dashdotdash.png");
m_pDashStyleListStore->add_item (pixbuf);
//m_pDashStyleListStore->add_item ("DashDotDash");
pixbuf = Gdk::Pixbuf::create_from_file ("dashedfunky.png");
m_pDashStyleListStore->add_item (pixbuf);
//m_pDashStyleListStore->add_item ("DashedFunky);
This compiles without any warnings (using -Wall). When I umcomment the text-based stuff and comment the pixbuf-based stuff everything works as expected, but just with text of course. Going with the pixbuf-based thing the critical Glib runtime-warning looks like this:
Quote:
GLib-GObject-WARNING **: unable to set property `text' of type `gchararray' from value of type `GdkPixbuf'
...
I get several of those... 34 to be exact. I wonder what's missing now... appreciating every further help somebody can provide!
Best regards...
MacSlow