gpt4 book ai didi

c - gtk 网格布局内的 Webkitgtk webview 无法正确显示

转载 作者:行者123 更新时间:2023-11-30 16:36:31 24 4
gpt4 key购买 nike

我正在尝试使用 gtk+ 和 webkitgtk 构建一个非常简单的浏览器。这需要典型浏览器所需要的东西:uri 栏、后退按钮、主页按钮和实际的网页显示区域。问题是 GTKWindow 最多只能有一个子部件。查看文档后,建议打包,特别是使用网格。我创建了网格布局,但是在运行代码时,我只看到左上角的文本框(地址栏),没有 webkitwebview。但是,如果我将行号和列号设置为与文本框相同,并将鼠标悬停在其上,将显示 webkitwebview 的真正压缩版本。如何让 webkitwebview 完全显示,同时在窗口中显示多个小部件?

gtk_init(&argc, &argv);

// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);

// create the gtk grid that'll set the layout and put grid in window
GtkWidget *grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(grid));

// create url_bar and add to grid
GtkWidget *url_bar = gtk_entry_new();
gtk_grid_attach(GTK_GRID (grid), url_bar, 0, 0, 1, 1);

// Create a browser instance and put in main window
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
gtk_grid_attach(GTK_GRID (grid), GTK_WIDGET (webView), 1, 1, 4, 4);

// Set up callbacks so that if either the main window or the browser instance is
// closed, the program will exit
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window);

// Load a web page into the browser instance
webkit_web_view_load_uri(webView, "http://webkitgtk.org");

// Make sure that when the browser area becomes visible, it will get mouse
// and keyboard events
gtk_widget_grab_focus(GTK_WIDGET(webView));

// Make sure the main window and all its contents are visible
gtk_widget_show_all(main_window);

// Run the main GTK+ event loop
gtk_main();enter code here

最佳答案

添加

gtk_widget_set_vexpand(GTK_WIDGET(webView), true);

关于c - gtk 网格布局内的 Webkitgtk webview 无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48414449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com