views:

197

answers:

1

I've looked in the gtk source code and the header height is private. I've tried something but it didn't work as wanted (the heightWithHeader is 1?!)

Glib::RefPtr<Gdk::Window> pWindow = treeView.get_bin_window();

treeView.set_headers_visible(true);
pWindow->get_size(width, heightWithHeader);

treeView.set_headers_visible(false);

pWindow->get_size(width, heightWithoutHeader);

r_treeView.set_headers_visible(true);

returnValue = heightWithHeader - heightWithoutHeader;

Can you help me with another solution or a fix to my code?

Update: I have to adjust the height of the treeview to display a fixed number of rows. I do this by adjusting the size of the container (a scrolledwindow) to headerHeight + numberRowsToDisplay * heightOfRow.

A: 

The reason your code doesn't work is very probably that you're being "too impatient", not giving GTK+ time to do the redraw of the widgets before you make the headers invisible again.

GTK+ doesn't draw immediately when you do a call that requires a redraw. Instead redraws are queued, and then done all at once from the GTK+ main loop. This way, doing two changes to widgets in sequence does not cause two redraws, but only one.

It's a bit of a hack, but you could try the "classic" GTK+ event-flushing trick, by inserting a loop like this after you turn on the headers:

while(gtk_events_pending())
  gtk_main_iteration();

This simply loops for as long as there are events in GTK+'s queue (the draw changes mentioned above are events, internally), and flushes them, then gives control back to you. This will very probably result in some visual flicker, though.

unwind
I have to adjust the height of the treeview to display a fixed number of rows. I do this by adjusting the size of the container (a scrolledwindow) to headerHeight + numberRowsToDisplay * heightOfRow.