gtk如何突出显示textview的下一行?

时间:2014-11-11 10:07:57

标签: textview gtk highlight

我必须只突出第二行(arr [ii + 1])。我尝试使用两个迭代器删除以前的标记,并将突出显示添加到新行,其他一个:

                                sprintf(bufferS,"%s",arr[ii]);

                            if(cuno==0)
                            {
                               gtk_text_buffer_get_end_iter(buffer, &ei);
                               gtk_text_buffer_insert(buffer, &ei, bufferS, -1);
                               gtk_text_buffer_get_end_iter(buffer, &ei);
                               gtk_text_buffer_insert(buffer, &ei, "\n", -1);
                               cuno++;
                            }

                               sprintf(bufferS2,"%s",arr[ii+1]);


                               gtk_text_buffer_create_tag(buffer, "gray_bg","background", "gray", NULL);
                               gtk_text_buffer_get_end_iter(buffer, &ei2);
                               gtk_text_buffer_get_end_iter(buffer, &ei);
                               gtk_text_buffer_insert(buffer, &ei2, bufferS2, -1);
                               gtk_text_buffer_get_end_iter(buffer, &ei2);
                               gtk_text_buffer_insert(buffer, &ei2, "\n", -1);
                               gtk_text_buffer_get_start_iter(buffer, &si2);
                               gtk_text_buffer_get_start_iter(buffer, &si);
                               gtk_text_buffer_remove_all_tags(buffer,&si, &ei);
                               gtk_text_buffer_apply_tag_by_name(buffer, "gray_bg",&si2, &ei2);

但在输出时,文字全部突出显示,有人可以帮助我吗?谢谢

1 个答案:

答案 0 :(得分:0)

已解决此问题,谢谢:)

   gtk_text_buffer_create_tag(buffer, "gray_bg","background", "green", NULL);
   gtk_text_buffer_get_iter_at_line(buffer,&si,ii+1);
   gtk_text_buffer_get_iter_at_line_offset (buffer,&ei2,ii+1,lstr);
   gtk_text_buffer_remove_tag_by_name (buffer,"gray_bg",&start,&end);
   gtk_text_buffer_apply_tag_by_name(buffer, "gray_bg",&si, &ei2);