如何获取gtktreeview header的高度?
我查看了 gtk 源代码,标头高度是私有的。 我已经尝试过一些方法,但它没有按预期工作(heightWithHeader 是 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;
你能帮助我找到另一个解决方案或修复我的代码吗?
更新:我必须调整树视图的高度以显示固定数量的行。 我通过将容器(滚动窗口)的大小调整为 headerHeight + numberRowsToDisplay * heightOfRow 来实现此目的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码不起作用的原因很可能是您“太不耐烦”,在使标题再次不可见之前没有给 GTK+ 时间来重新绘制小部件。
当您进行需要重绘的调用时,GTK+ 不会立即进行绘制。 相反,重绘会排队,然后从 GTK+ 主循环一次性完成。 这样,按顺序对小部件进行两次更改不会导致两次重绘,而只会导致一次。
这有点像黑客,但您可以尝试“经典”GTK+ 事件刷新技巧,通过在打开标头后插入这样的循环:
只要 GTK+ 的队列中有事件(绘制上面提到的更改是事件(内部),并刷新它们,然后将控制权交还给您。 不过,这很可能会导致一些视觉闪烁。
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:
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.