sassc: error while loading...
Continue reading...Gtk
Gtk 修改GtkLabel、GtkEntry等的文本颜色,添加下划线,更改字体大小等相关属性
代码如下,将Widget传进函数即可,之后相关属性会相应改变.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
GtkWidget *setWidgetProperties( GtkWidget *entry ) { PangoAttrList *pangoAttrList = pango_attr_list_new(); PangoAttribute *pangoAttribute = pango_attr_weight_new ( PANGO_WEIGHT_BOLD ); pango_attr_list_insert ( pangoAttrList, pangoAttribute ); /* Set bold type*/ pangoAttribute = pango_attr_underline_new(PANGO_UNDERLINE_LOW); pango_attr_list_insert ( pangoAttrList, pangoAttribute ); pangoAttribute = pango_attr_underline_color_new(0x00, 0xc7ff, 0xffff); /* Color Cyan*/ pango_attr_list_insert ( pangoAttrList, pangoAttribute ); pangoAttribute = pango_attr_scale_new( 1.5 ); /* Set font size*/ pango_attr_list_insert ( pangoAttrList, pangoAttribute ); GdkRGBA rgbacolor = { 0, 0, 0, 1 }; /* rgb a: black*/ gtk_widget_override_color( entry, 0, &rgbacolor); gtk_entry_set_attributes ( GTK_ENTRY(entry), pangoAttrList ) ; return entry; } |
详情见注释 也可以进一步封装,根据widget类型,自动调整逻辑,同时适应Entry和Label等的属性设置:...
Continue reading...记录一次奇怪的段错误经历
背景: GTK编程,在函数内部定义了一个结构体,作为指针传递给其他函数,在其他函数内部调用结构体内部成员变量,发现有一个成员变量总是为空,另外一个不会。 原因:...
Continue reading...Gtk TextView 如何去除白色背景框
Gtk TextView在某些情况下显示的文字会有白色的背景框,显得跟界面格格不入,如下图所示: 上图的源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <gtk/gtk.h> gboolean key_press ( GtkWidget *window, GdkEventKey *event, gpointer *data ); int main(int argc, char **argv) { GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 400, 300); gtk_window_set_title(GTK_WINDOW(window), ""); GtkWidget *view = gtk_text_view_new(); GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); gtk_text_buffer_set_text ( buf, "窗含西岭千秋雪\n门泊东吴万里船", -1); gtk_text_view_set_editable ( GTK_TEXT_VIEW(view), FALSE ); GtkWidget *hBox = gtk_box_new ( GTK_ORIENTATION_VERTICAL, 0 ); gtk_container_add ( GTK_CONTAINER(window), hBox ); gtk_box_pack_start (GTK_BOX(hBox), view, 0, 0, 0); //GdkColor windowColor = gtk_widget_get_style(window)->bg[GTK_STATE_NORMAL]; //gtk_widget_modify_bg ( view, GTK_STATE_NORMAL, &windowColor ); g_signal_connect(G_OBJECT(window), "destroy", \ G_CALLBACK(gtk_main_quit),NULL); g_signal_connect(G_OBJECT(window), "key-press-event", \ G_CALLBACK(key_press),NULL); gtk_widget_show_all(window); gtk_main(); return 0; } gboolean key_press ( GtkWidget *window, GdkEventKey *event, gpointer *data ) { if ( event->state == GDK_CONTROL_MASK ) { if ( event->keyval == GDK_KEY_c) { gtk_main_quit(); } } } |
...
Continue reading...记一次Gtk编程遇到问题的解决过程 (GtkSearchEntry绑定新的快捷键,信号发生快捷键)
最近用到GtkSearchEntry的编程,其中一个信号是stop-search,对应绑定的默认快捷键是ESC,一般捕获为退出信号,感觉不顺手,想绑定到Ctrl-C,中途遇到了问题,查看全网没有发现解决方案,但是从StackOverFlow的这篇文章里找到一点灵感 Gtk3 keys bindings in...
Continue reading...Vim获取特定行作为字符串复制给变量
let headTxt=getline(1) 获取第一行赋值给字符串headTxt
1 2 3 4 5 6 7 8 9 10 11 |
if &filetype == "c" let headTxt=getline(1) if headTxt == "#include <gtk/gtk.h>" exec "!gcc `pkg-config --cflags --libs gtk+-3.0` % -o %<" exec "!./%<" else exec "!gcc % -o %< -lm -lreadline" exec "!./%<" endif |
...
Continue reading...