[gtkmm] suffering from slow treeview



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);
}


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