Re: [gtkmm] suffering from slow treeview



gtkmm-list wrote:

Thanks for the suggestion, it does speed thing up, but afais only when
you use a single color. I need alternating colors ( green,red,yellow) to
indicate the states of persons in list. And for that i need the line in Add() .

However, i found another solution for my problem today. i now use some
images from the Gtk::Stock collection icw render_icon() to indicate a
state. It's as clear as backgroundcolors and performance is MUCH better.

Still, i'm curious if there is a solution to this slow background
drawing. Any more ideas?
Maybe you still don't understand how the CellRendererText works (I must admit that I barely understand it myself).

Here is a snip from my code that has colored rows in a treeview where each row can be a different color. Maybe this will help explain it better.

   ... <snip code that appends multiple columns to my treeview.
int cols_count = m_TreeView->append_column("DC Date", schedule_columns.dc_date); // Description: ADD FOREGROUND COLOR PROPERTY TO THE ROWS.
   //
// The last column appended to the tree view ("DC Date") tells us the total // number of columns. In our case, all of the columns are CellRendereText
   // if this is not the case in the future (i.e. you are changing this
   // section) then keep that in mind.
   //
// Loop through the columns and tell each column's cellrenderer to use the
   // value in the color column to change the foreground_gdk property for
   // the row.
   //
   // for each column in the treeview
   for (int i = 0; i < cols_count; i++)
   {
       Gtk::TreeViewColumn* pColumn = m_TreeView->get_column(i);
       if (pColumn)
       {
           // Get the cellrenderer (assuming it's TEXT)
           Gtk::CellRendererText* pRenderer = static_cast
<Gtk::CellRendererText*> (pColumn->get_first_cell_renderer()); // Tell the renderer to use the 'color' column to set the
           // foreground_gdk color property.
           pColumn->add_attribute (pRenderer->property_foreground_gdk(),
                                   schedule_columns.color);
       }
   }

Bart




On Thu, 2004-04-01 at 18:37, Jeffrey S. Gavin wrote:
move this line:

color_column->add_attribute(cell_renderer_text->property_background(), columns.color);

to the constructor, underneath the line:

cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>(cell_renderer);

and your performance issue goes away (I have tested it already).


You only need to set to set the cellrenderertext once (you set it for the entire column), not for each row.

Jeff

gtkmm-list wrote:

Hi listmembers,

I lately stumbled upon this most annoying problem when i start using
colors in my treeview. The time to fill the Treestore is considerably
longer if you use colors and after performing some changes, it gets
worse. Has anyone experienced similar problems?

Maybe it's a bad implemation from my side ( i hope so ) or is this a
common issue?

Attached to this mail is a small demo i wrote to illustrate the problem.
Click the button "refresh" a couple of times ( 5 -15 depending on your
hardware ) and you'll notice the slowdown.

btw, i use gtkmm 2.2.8

thanks in advance,

Bart



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

#include <gtkmm.h>


class DemoTree : public Gtk::TreeView
{
private:
struct Columns : public Gtk::TreeModelColumnRecord {
		Gtk::TreeModelColumn<std::string> column1;
		Gtk::TreeModelColumn<std::string> color;
		Columns() { add(column1);add(color); }
	};
	Columns columns;
	
	Gtk::CellRendererText* cell_renderer_text;
	Gtk::TreeViewColumn* color_column;
	Gtk::TreeRow row;
	
		
public:
	Glib::RefPtr<Gtk::TreeStore> treestore;
		
	DemoTree()
	{
		treestore = Gtk::TreeStore::create( columns );
		set_model( treestore );
						
		append_column("DemoColumn", columns.column1);
		
		color_column = get_column(0);
		Gtk::CellRenderer* cell_renderer = color_column->get_first_cell_renderer();
		cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>(cell_renderer);
	}
	
	void AddRow( std::string name )
	{		
		row = *(treestore->append());
		row[columns.color] = "red";
		
		color_column->add_attribute(cell_renderer_text->property_background(), columns.color);
		
		row[columns.column1] = name;
	}


};

class DemoWindow : public Gtk::Window
{
	DemoTree dt;
	Gtk::ScrolledWindow scroll_window;
	Gtk::VBox vbox_main;
	Gtk::Button btn_Refresh;
	
public:	
	DemoWindow()
	{
		set_default_size( 400, 600 );
		
		scroll_window.add( dt );
		scroll_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
		vbox_main.pack_start( scroll_window );
		
		btn_Refresh.set_label("Refresh");
		btn_Refresh.signal_clicked().connect( SigC::slot(*this, &DemoWindow::btn_refresh_click) );
		vbox_main.pack_start( btn_Refresh, Gtk::PACK_SHRINK );
		
		
		btn_refresh_click();//fill 'er up :P
			
		add(vbox_main);
		show_all_children();
	}
	
	void btn_refresh_click()
	{
		dt.treestore->clear();
		for(int i=0;i<200;i++) dt.AddRow( "TESTING");
	}
};


int main(int argc, char *argv[])
{
	Gtk::Main kit(argc, argv);
DemoWindow dw;
  Gtk::Main::run(dw);
}


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
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]