如何获取gtktreeview header的高度?

发布于 2024-07-20 06:16:56 字数 600 浏览 5 评论 0原文

我查看了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-07-27 06:16:56

您的代码不起作用的原因很可能是您“太不耐烦”,在使标题再次不可见之前没有给 GTK+ 时间来重新绘制小部件。

当您进行需要重绘的调用时,GTK+ 不会立即进行绘制。 相反,重绘会排队,然后从 GTK+ 主循环一次性完成。 这样,按顺序对小部件进行两次更改不会导致两次重绘,而只会导致一次。

这有点像黑客,但您可以尝试“经典”GTK+ 事件刷新技巧,通过在打开标头后插入这样的循环:

while(gtk_events_pending())
  gtk_main_iteration();

只要 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文