GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 16, 2014 9:29 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Q: What approach is need to have Pixbufs used in a ComboBox?
PostPosted: Sun Sep 25, 2005 2:29 pm 
Offline
Familiar Face

Joined: Wed Sep 21, 2005 4:14 am
Posts: 17
Location: Aachen, Germany
Once again greetings to everybody!

I'm unable to comprehend the manual of gtkmm while trying to figure out how to go about having a Gtk::ComboBox use Gdk::Pixbuf or Gtk::CellRendererPixbuf (not sure which is right for the job) for its entries. First I tried to guess my way through it using a Gtk::TreeView... then I was told to look out for Gtk::CellLayout... to be honest I'm totally lost... my head is spinning like mad and my brain smokes liked burning rubber. I have tried everything I could think of for several hours now. Also trying to google the globe for hints on this issue didn't yield and new insights.

If anyone has such an example at hand or knows where to find example sourcecode to this, please drop me a line here!

Thanks in advance for your time and kind help!

Best regards...

MacSlow

_________________
First they ignore you...
then they laugh at you...
then they fight you...
then you win!
(Gandhi)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 25, 2005 7:02 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Once again, I'm still wet behind the ears so I have no solution for you. However, in my travels I have done some reading about using a GtkTreeView and although I never wrote any code myself, I seem to remember something about the cell renderer being able to have a pixbuff and the text packed into like a container. Can't quite recall-- but I'm sure it's similar to what you are trying to do? The tutorial I read was GTK+ 2.0 Tree View Tutorial and was in C. May have some hints there.

[/url]

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: I got this far... but it's still not far enough.
PostPosted: Sun Sep 25, 2005 11:19 pm 
Offline
Familiar Face

Joined: Wed Sep 21, 2005 4:14 am
Posts: 17
Location: Aachen, Germany
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

_________________
First they ignore you...
then they laugh at you...
then they fight you...
then you win!
(Gandhi)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group