2

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.

abergmeier
  • 13,224
  • 13
  • 64
  • 120
  • 1
    I have the same problem as you, can you please share with me what didi you do? – RRR Aug 27 '13 at 13:11
  • 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 '13 at 15:57

3 Answers3

1

You can try the QT WebKit if you need just a embed browser

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

gariel
  • 687
  • 3
  • 13
1
    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.

cryfeifei
  • 29
  • 4
  • 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](https://stackoverflow.com/help/how-to-answer), and also [Explaining entirely code-based answers](https://meta.stackexchange.com/questions/114762/explaining-entirely-%E2%80%8C%E2%80%8Bcode-based-answers) – Anh Pham Nov 06 '18 at 01:31
1

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:

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

  2. 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.

  3. 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.

Romário
  • 1,664
  • 1
  • 20
  • 30