如何手动绘制GtkTreeView扩展器 [英] How to manually draw the GtkTreeView expander
问题描述
我正在使用GtkTreeView
小部件,并且想要更改用于打开和关闭子行的"expander"图标的外观:我希望这些图标成为大家都熟悉的三角形,但是它们而是显示为带方框的"+"和-"符号.
I'm using a GtkTreeView
widget and I want to change the appearance of the "expander" icon that opens and closes child rows: I want the icons to be the triangels that we're all familiar with, but they're appearing as boxed "+" and "-" symbols instead.
起初我以为必须要设置一个样式枚举,但是找不到.然后,我想也许可以在主题的gtkrc文件中设置一个样式属性,但我认为没有.最后,我采取了尝试像这样手动覆盖draw方法的方法:
At first I thought there must be a style enumeration that I can set, but I cannot find one. Then, I thought maybe there's a style property I can set in my theme's gtkrc file, but I don't think there is one. Finally, I resorted to trying to manually override the draw method like so:
GtkWidget *pTreeView = gtk_tree_view_new_with_model((GtkTreeModel *)pTreeModel);
(GTK_STYLE_GET_CLASS(pTreeView->style))->draw_expander = my_draw_expander_override;
但是my_draw_expander_override()
从未被调用,并且扩展器仍然是带框的"+"和-"图标.
But my_draw_expander_override()
never gets called and the expanders are still the boxed "+" and "-" icons.
有人知道如何更改GtkTreeView
扩展器图标的外观或自己绘制吗?
Does anyone know how can I change the appearance of the GtkTreeView
expander icons or just draw them myself?
预先感谢一堆!
推荐答案
此处是如何覆盖draw_expander的示例代码.您肯定需要阅读手册才能正确使用所有参数.
Here the sample code of how to overwrite draw_expander. You'll definetely have to take a look in the manual to get all the parameters right.
#include <gtk/gtk.h>
#include <cairo.h>
enum {
COL_1,
N_COLS
};
void draw_expander (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
GtkExpanderStyle expander_style) {
cairo_t *cr;
cr = gdk_cairo_create (window);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, 0, 10);
cairo_line_to (cr, 10, 5);
cairo_close_path (cr);
cairo_stroke (cr);
}
GtkWidget *build_view (); /* just supply your own */
int main (int argc, char *argv[]) {
gtk_init (&argc, &argv);
GtkWidget *window;
GtkWidget *view;
window = g_object_new (GTK_TYPE_WINDOW, NULL);
view = build_view ();
gtk_container_add (GTK_CONTAINER (window), view);
GtkStyle *style = gtk_widget_get_style (view);
GtkStyleClass *klass = GTK_STYLE_GET_CLASS (style);
klass->draw_expander = draw_expander;
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
这篇关于如何手动绘制GtkTreeView扩展器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!