添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I need to develop an application for Windows , Linux and Mac . To not have to write all the window cruft myself I chose to use Qt5 (over wxWidgets , because the latter ship no precompiled binaries). I have a GTK Widget (of Cef ) which I now need to embed, but sadly have no idea how.

There seems to have been QX11EmbedContainer in previous versions of Qt , but it is not present anymore and also I am not sure this works, when there is a switch to Weyland .

I did use Qt Webkit. It works fairly well but since there is no version beyond 4.8 for Ubuntu LTS I am stuck with that. abergmeier Aug 30, 2013 at 15:57
    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);

you can use QX11EmbedContainer class on Qt4.

Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers – Anh Pham Nov 6, 2018 at 1:31

It's been 7 years, but I've dealt with this before. Here's what I found1:

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.

    I highly recommend anyone still trying this to take a look at the entire thread1. QtWebkit is not longer an acceptable solution, while CEF centainly is.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •