GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Q: What approach is need to have Pixbufs used in a ComboBox?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
MacSlow
Familiar Face


Joined: 21 Sep 2005
Posts: 17
Location: Aachen, Germany

PostPosted: Sun Sep 25, 2005 2:29 pm    Post subject: Q: What approach is need to have Pixbufs used in a ComboBox? Reply with quote

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
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Sun Sep 25, 2005 7:02 pm    Post subject: Reply with quote

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]
Back to top
MacSlow
Familiar Face


Joined: 21 Sep 2005
Posts: 17
Location: Aachen, Germany

PostPosted: Sun Sep 25, 2005 11:19 pm    Post subject: I got this far... but it's still not far enough. Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

    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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP