Re: Background Color!!



There may be better ways to do this, but this is one option:
-----------------------------------
#include <gtkmm.h>
#include <gdkmm.h>

class myVBox : public Gtk::VBox
{
    public:
        myVBox(void)
        {
            m_color = new Gdk::Color("red");
            Glib::RefPtr<Gdk::Colormap> map = get_default_colormap();
            map->alloc_color(*m_color);
        }

        virtual ~myVBox(void)
        {
            delete m_color;
        }

        bool on_expose_event(GdkEventExpose* event)
        {
            Glib::RefPtr<Gdk::Window> win = get_window();
            win->set_background(*m_color);
            win->clear();
            return true;
        }

    private:
        Gdk::Color* m_color;
};


int main(int argc, char** argv)
{
    Gtk::Main kit(argc, argv);
    Gtk::Window win;
    myVBox boxBase;

    win.add(boxBase);
    win.show_all();
    Gtk::Main::run(win);
}

----------------------------------------------------------------

On 2/11/06, jalqadir netscape net <jalqadir netscape net> wrote:
>
>
> Hi folks!
> I'd like to add background color to a VBox, but I am a bit confused about
> how to go about it.
> This is what I'd like to do
>  ---snip---
>  Gtk::VBox* boxBase;
>  Gdk::Color bgColor("red");
>  Gdk::Colormap* map;
>  map->alloc_color();
>  boxBase         = Gtk::manage(new Gtk::VBox());
>  boxBose->modify_bg(Gtk::STATE_NORMAL, bgColor);
>  ---end---
> Needless to say, this does not work!
> After a little bit or reading I found that the 'string' passed to Gtk::Color
> must be one described in a file called 'rgb.txt', but I could not find this
> file.
> I'd appreciate if someone here could give me a breathing and living example.
>
> TIA
>
> * You cannot exercise your power to a point of humiliation.
> - Jean Chretien
>
> * It's amazing how the small seeds of distrust and misunderstanding
> can yield a crop of hate and death...
>
> * If that document has fine printing anywhere, just chuck it in the garbage
> - Jorge Escalante
> Ma'assalama! Adiós! bye! ________________________________
>  Try the New Netscape Mail Today!
>  Virtually Spam-Free | More Storage | Import Your Contact List
> http://mail.netscape.com
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>
>



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