关于qt5:将GTK窗口小部件嵌入Qt窗口

Embed a GTK Widget into a Qt Window

我需要为Windows,Linux和Mac开发一个应用程序。 为了不必自己编写所有窗口碎片,我选择使用Qt5(通过wxWidgets使用,因为后者没有预编译的二进制文件)。 我有一个现在需要嵌入的(Cef的)GTK Widget,但可悲的是不知道如何。

在以前的Qt版本中似乎有QX11EmbedContainer,但是现在不存在了,而且当切换到Weyland时,我不确定这是否可行。


如果您只需要嵌入式浏览器,则可以尝试QT WebKit

http://qt-project.org/doc/qt-5.0/qtwebkit/qtwebkit-index.html


已经有7年了,但是我之前已经处理过了。 这是我发现的1:

I found a way to properly embed CEF inside a Qt window: embedding it inside an empty QWindow instead of a QWidget. There are some caveats, though:

  • To add the CEF window into a QWidget layout, you will need to use QWidget::createWindowContainer()

  • An empty QWindow doesn't render anything -- not even a background. So, you might need to use a QBackingStore to make it render something when CEF isn't embedded -- see the Raster Window example for some reference.

  • You might need to use the winId from before you add the QWindow into your widget's layout.

  • 我强烈建议任何仍在尝试此操作的人来看看整个线程1。 QtWebkit不再是一种可接受的解决方案,而CEF恰恰是。


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
        QMainWindow* main_window = new QMainWindow;
        QX11EmbedContainer* container = new QX11EmbedContainer;
        main_window->setCentralWidget(container);

        //gtk code
        GtkWidget* window;
        GtkWidget* button;
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        button = gtk_button_new ();
        gtk_widget_show (button);
        gtk_container_add (GTK_CONTAINER (window), button);
        gtk_widget_show(window);
        XID id = GDK_WINDOW_XWINDOW (GTK_WIDGET(window)->window);

        container->embedClient(id);

    您可以在Qt4上使用QX11EmbedContainer类。