Re: Line space between rows of a Gtk::TreeView - HOW?



Thanks for the answer

no I want to control the space between two rows in a TreeView,

i finally found the
Gtk::CellRenderer->property_ypad()

that seems to control that. Is that correct?

Yet, I am also trying to set  a fixed number of visible lines in my TreeView:
i did it this way: (where r_widget is the Gtk::TreeView)

void MyStringListView::setHeightInRows(int nbRows)
{
   Gtk::CellRenderer *renderer = r_widget->get_column_cell_renderer(0);

   renderer->property_ypad() = 0;

   int y_offset, x_offset, width, height;
   Gdk::Rectangle cell_area;

   renderer->get_size(*r_widget,
                               cell_area,
                               x_offset,
                               y_offset,
                               width,
                               height);

   r_widget->set_size_request(-1, nbRows * (height+4));             // WHY +4?
}


And i do not understand why I have to add 4 to the height but anyway that gives me the correct result for any nbRows and any font.
Do you know why?




On Nov 13, 2007 5:32 PM, Iker Perez de Albeniz <ialbeniz cbt es> wrote:

Hi,



I don t know if a have understand correctly... you want to drwa a

Gtk::HSeparator like line??





if you want to do this you have to do with a CellRenderer... adding this

lineas to the "render_vfunc"





/***************************************************************/

Glib::RefPtr<Gdk::GC> line1GC = Gdk::GC::create(window);

line1GC->set_rgb_fg_color(m_Color1);



window->draw_line(line1GC,begining_x,begining_y,end_x, end_y);



Glib::RefPtr<Gdk::GC> line2GC = Gdk::GC::create(window);

line2GC->set_rgb_fg_color(m_Color2);



window->draw_line(line2GC,0,begining_x,begining_y,end_x, end_y);

/****************************************************************/



for example in my own cellrenderer the "render_vfunc" looks like that:



/**********************************************************************/



void CellRendererComent::render_vfunc(const Glib::RefPtr<Gdk::Drawable>&

window, Gtk::Widget& widget, const Gdk::Rectangle& background_area, const

Gdk::Rectangle& cell_area, const Gdk::Rectangle& expose_area,

Gtk::CellRendererState flags)

{

       //LOG("Calling render_vfunc");

       const unsigned int cell_xpad = property_xpad();

       const unsigned int cell_ypad = property_ypad();



       int x_offset = 0, y_offset = 0, width = 0, height = 0;

       this->get_size(widget, cell_area, x_offset, y_offset, width, height);



       width -= cell_xpad * 2;

       height -= cell_ypad * 2;



       if (width <= 0 || height <= 0)

               return;



       Gtk::StateType state = Gtk::STATE_INSENSITIVE;



       if (flags & Gtk::CELL_RENDERER_SELECTED != 0)

       {

               state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;

       }







       //Cast the drawable to a Window.

       Glib::RefPtr<Gdk::Window> window_casted =

Glib::RefPtr<Gdk::Window>::cast_dynamic<>(window);

       if(window)

       {

               Gdk::Color m_Color;

               m_Color.set_red(0);

               m_Color.set_blue(65535);

               m_Color.set_green(65535);



               Gdk::Color m_Color1;

               m_Color1.set_red(4369);

               m_Color1.set_blue(4369);

               m_Color1.set_green(4369);



               Gdk::Color m_Color2;

               m_Color2.set_red(25700);

               m_Color2.set_blue(22102);

               m_Color2.set_green(23387);



               int rend_w, rend_h;



               Glib::RefPtr<Gdk::Pixbuf> image;

               const bool cheked = property_checked();



               if(cheked){

               image =

Gdk::Pixbuf::create_from_file("./pixmaps/machineMovement/comments_arrow.png");

               }else{

               image =

Gdk::Pixbuf::create_from_file("./pixmaps/machineMovement/comments_arrow-n.png");

               }



               Glib::RefPtr<Gdk::Colormap> refCmap = widget.get_default_colormap();

               refCmap->alloc_color(m_Color);

               Glib::RefPtr<Gdk::GC> refGC = Gdk::GC::create(window);

               refGC->set_foreground(m_Color);



               window->get_size(rend_w, rend_h);

               //window->draw_rectangle(refGC,true, , cell_area.get_y() + y_offset +

cell_ypad,image->get_width(), image->get_height());

               window->draw_pixbuf(refGC, image, 0, 0,288/*cell_area.get_x() + x_offset

+ cell_xpad*/, cell_area.get_y() + y_offset + cell_ypad - 5,

image->get_width(), image->get_height(),Gdk::RGB_DITHER_NONE, 0, 0);





               Glib::RefPtr<Gdk::GC> line1GC = Gdk::GC::create(window);

               line1GC->set_rgb_fg_color(m_Color1);



               window->draw_line(line1GC,0,cell_area.get_y()+26,295,cell_area.get_y()+26);



               Glib::RefPtr<Gdk::GC> line2GC = Gdk::GC::create(window);

               line2GC->set_rgb_fg_color(m_Color2);



               window->draw_line(line2GC,0,cell_area.get_y()+27,295,cell_area.get_y()+27);



       }

}





/*************************************************************************/



I hope this will help you!!



On Tue, 13 Nov 2007 15:15:50 +0100, "Yannick Barbeaux"

<ybarbeaux gmail com> wrote:

> How is it possible to control the line space between the rows of a

> Gtk::TreeView?

> (my TreeView is in fact a simple string list view so it should be easy

> but i cannot find anything about that in the (poor) gtk documentation)

>

> with CellRenderer?

>

> Thanks

>

> Yannick




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