我试过了 gtk_set_text_view_editable(GTK_TEXT_VIEW(outputfield),FALSE); 但它不起作用。也许我把它放在错误的地方,gtk对订单非常敏感,不知道。这是一个缓冲的文本视图。
有人有想法吗?
修改
很抱歉cpoy粘贴所有东西,但到目前为止我不知道问题出在哪里我不知道该遗漏什么。
我的代码是:
GtkTextBuffer *output_buffer;
GtkTextBuffer *input_buffer;
static gboolean delete(GtkWidget *widget, GtkWidget *event, gpointer data)
{
gtk_main_quit();
printf("Viszlát és kössz a halakat!\n");
return FALSE;
}
static void cnt_btn_clicked(GtkWidget *widget, gpointer data)
{
gchar* msg = "Connect button clicked\n";
gtk_text_buffer_insert_at_cursor(output_buffer,msg,strlen(msg));
}
static void dcnt_btn_clicked(GtkWidget *widget, gpointer data)
{
gchar* msg = "Disconnect button clicked\n";
gtk_text_buffer_insert_at_cursor(output_buffer,msg,strlen(msg));
}
static void read_btn_clicked(GtkWidget *widget, gpointer data)
{
gchar* msg = "Read button clicked\n";
gtk_text_buffer_insert_at_cursor(output_buffer,msg,strlen(msg));
}
static void aut_btn_clicked(GtkWidget *widget, gpointer data)
{
gchar* msg = "Automatic button clicked\n";
gtk_text_buffer_insert_at_cursor(output_buffer,msg,strlen(msg));
}
static void write_btn_clicked(GtkWidget *widget, gpointer data)
{
gchar* msg = "Write button clicked\n";
gtk_text_buffer_insert_at_cursor(output_buffer,msg,strlen(msg));
}
static void activate (GtkApplication *app, gpointer user_data)
{
//--Containers--
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *frame;
GtkWidget *main_hbox;
GtkWidget *main_leftvbox;
GtkWidget *main_rightvbox;
GtkWidget *input_scrollwindow;
GtkWidget *output_scrollwindow;
//--Design--
GdkRGBA bg_window;
bg_window.red = 0.95;
bg_window.green = 0.95;
bg_window.blue = 0.95;
bg_window.alpha = 1;
GdkRGBA bg_output;
bg_output.red = 0.9765625;
bg_output.green = 0.9375;
bg_output.blue = 0.8203125;
bg_output.alpha = 1;
GdkRGBA bg_input;
bg_input.red = 1;
bg_input.green = 1;
bg_input.blue = 1;
bg_output.alpha = 1;
//--Components--
GtkWidget *main_label;
GtkWidget *settings_label;
//--Main window--
GtkWidget *hseparator1;
GtkWidget *hseparator2;
//checkbuttons (checkboxes)
GtkWidget *checkbutton_uart;
GtkWidget *checkbutton_i2c;
GtkWidget *checkbutton_spi0;
GtkWidget *checkbutton_spi1;
GtkWidget *checkbutton_ndef;
//buttons
GtkWidget *btn_cnt;
GtkWidget *btn_dcnt;
GtkWidget *btn_read;
GtkWidget *btn_aut;
GtkWidget *btn_write;
//textfields (textviews)
GtkWidget *outputfield;//not editable
GtkWidget *inputfield;//editable
//--Settings window--
window = gtk_application_window_new (app);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
g_signal_connect(window, "delete-event", G_CALLBACK(delete), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
notebook = gtk_notebook_new();
//table = gtk_table_new(1,6,TRUE);
gtk_container_add(GTK_CONTAINER(window),notebook);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
gtk_widget_override_background_color(GTK_WIDGET(notebook), GTK_STATE_NORMAL, &bg_window);
gtk_widget_show(notebook);
//--Main tab--
frame = gtk_frame_new(" Controll NFC devices ");
gtk_container_set_border_width(GTK_CONTAINER(frame),10);
gtk_widget_set_size_request(frame,910,610);
gtk_widget_show(frame);
main_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
//--Creating elements in left box--
main_leftvbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
checkbutton_uart = gtk_check_button_new_with_label(" UART");
checkbutton_i2c = gtk_check_button_new_with_label(" I2C");
checkbutton_spi0 = gtk_check_button_new_with_label(" SPI0.0");
checkbutton_spi1 = gtk_check_button_new_with_label(" SPI0.1");
hseparator1 = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
checkbutton_ndef = gtk_check_button_new_with_label(" NDEF");
hseparator2 = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
btn_cnt = gtk_button_new_with_label("Connect");
g_signal_connect(btn_cnt, "clicked", G_CALLBACK(cnt_btn_clicked), NULL);
btn_dcnt = gtk_button_new_with_label("Disconnect");
g_signal_connect(btn_dcnt, "clicked", G_CALLBACK(dcnt_btn_clicked), NULL);
btn_read = gtk_button_new_with_label("Read");
g_signal_connect(btn_read, "clicked", G_CALLBACK(read_btn_clicked), NULL);
btn_aut = gtk_button_new_with_label("Automatic");
g_signal_connect(btn_aut, "clicked", G_CALLBACK(aut_btn_clicked), NULL);
btn_write = gtk_button_new_with_label("Write");
g_signal_connect(btn_write, "clicked", G_CALLBACK(write_btn_clicked), NULL);
//--Placing elements in left box--
gtk_box_pack_start(GTK_BOX(main_leftvbox), checkbutton_uart, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_leftvbox), checkbutton_i2c, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_leftvbox), checkbutton_spi0, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_leftvbox), checkbutton_spi1, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_leftvbox), hseparator1, FALSE, FALSE, 3);
gtk_box_pack_start(GTK_BOX(main_leftvbox), checkbutton_ndef, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_leftvbox), hseparator2, FALSE, FALSE, 3);
gtk_box_pack_start(GTK_BOX(main_leftvbox), btn_cnt, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(main_leftvbox), btn_dcnt, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(main_leftvbox), btn_read, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(main_leftvbox), btn_aut, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(main_leftvbox), btn_write, FALSE, FALSE, 40);
//--Creating elements in right box--
main_rightvbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
output_scrollwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(output_scrollwindow),752);
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(output_scrollwindow),410);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(output_scrollwindow), GTK_SHADOW_ETCHED_IN);
outputfield = gtk_text_view_new();
gtk_widget_set_size_request(GTK_WIDGET(outputfield), 790,320);
gtk_widget_override_background_color(GTK_WIDGET(outputfield), GTK_STATE_NORMAL, &bg_output);
output_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(outputfield));
gtk_container_add(GTK_CONTAINER(output_scrollwindow), outputfield);
gtk_text_view_set_editable(GTK_TEXT_VIEW(outputfield), FALSE);
input_scrollwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(input_scrollwindow),752);
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(input_scrollwindow),120);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(input_scrollwindow), GTK_SHADOW_ETCHED_IN);
inputfield = gtk_text_view_new();
gtk_text_view_set_editable(GTK_TEXT_VIEW(outputfield), TRUE);
gtk_widget_set_size_request(GTK_WIDGET(inputfield), 790,115);
input_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(inputfield));
gtk_widget_override_background_color(GTK_WIDGET(inputfield), GTK_STATE_NORMAL, &bg_input);
gtk_container_add(GTK_CONTAINER(input_scrollwindow), inputfield);
//--Placing elements in right box--
gtk_box_pack_start(GTK_BOX(main_rightvbox), output_scrollwindow, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_rightvbox), input_scrollwindow, FALSE, FALSE, 5);
//--Placing vertical conatiners in the main box
gtk_box_pack_start(GTK_BOX(main_hbox), main_leftvbox, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(main_hbox), main_rightvbox, FALSE, FALSE, 5);
gtk_container_add(GTK_CONTAINER(frame), main_hbox);
main_label = gtk_label_new(" Main ");
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, main_label);
//---Settings tab--
frame = gtk_frame_new(" Setup Environment and Devices ");
gtk_container_set_border_width(GTK_CONTAINER(frame),5);
gtk_widget_set_size_request(frame,910,610);
gtk_widget_show(frame);
settings_label = gtk_label_new("Settings Components");
gtk_container_add(GTK_CONTAINER(frame), settings_label);
gtk_widget_show(settings_label);
settings_label = gtk_label_new("Settings");
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, settings_label);
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
gtk_window_set_title (GTK_WINDOW (window), "NFC-Reader v0.4");
gtk_widget_show_all(window);
gtk_main();
}
int main(int argc, char **argv)
{
GtkApplication *app;
int status;
gtk_init(&argc, &argv);
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_signal_connect( app, "delete_event", G_CALLBACK(gtk_window_iconify),NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);//drill1 no;mill no;drill2 yes;temper yes
return status;
}
答案 0 :(得分:1)
再次检查您的代码。我相信您的意思是将输入字段设置为可编辑,但实际上您在将输出字段设置为不可编辑后将其设置为可编辑。搜索所有outputfield
出现的代码并检查每个代码。这是常见的复制粘贴错误。
你有
...
gtk_text_view_set_editable(GTK_TEXT_VIEW(outputfield), FALSE);
...
inputfield = gtk_text_view_new();
gtk_text_view_set_editable(GTK_TEXT_VIEW(outputfield), TRUE);
...
答案 1 :(得分:0)
找到了一个可能的解决方案:
我已使用以下行将窗口小部件的敏感度设置为不敏感:
gtk_widget_set_sensitive(GTK_WIDGET(outputfield),FALSE);
在此之后你必须改变文本的颜色,因为默认情况下几乎是白色。使用以下行,您可以这样做:
GdkRGBA text_color;
gdk_rgba_parse (&text_color, "black");
gtk_widget_override_color (outputfield, GTK_STATE_FLAG_INSENSITIVE, &text_color)
现在它有效......
我还在等待那个不那么棘手的选择。