1

I am trying to to embed a QWebview from one process into another process's window. I want the background of the containing window to show through the contained webview.

test.cpp:

#define EMBEDDING 1

#include <QtCore>
#include <QtGui>
#include <QtWebKit>
#include <QX11EmbedWidget>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

#if EMBEDDING == 1

    QX11EmbedWidget *parent = new QX11EmbedWidget();

#else

    QWidget *parent = new QWidget();

#endif


    parent->show();

    QWebView *web = new QWebView(parent);

    parent->setAttribute(Qt::WA_TranslucentBackground);

    QWebPage *page = web->page();
    QPalette palette = page->palette();
    palette.setBrush(QPalette::Base, Qt::transparent);
    page->setPalette(palette);


#if EMBEDDING == 1

    parent->embedInto(atoi(argv[1]));

#endif

    page->currentFrame()->documentElement().setInnerXml("text");

    web->show();
    parent->show();

    return app.exec();
}

test2.cpp:

#include <QtCore>
#include <QtGui>
#include <iostream>


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget *parent = new QWidget();

    parent->setStyleSheet("background-color: yellow;");

    parent->show();
    parent->move(100,100);


    std::cout << "Winid: " << parent->winId() << "\n";

    return app.exec();
}

I built these on Ubuntu 12.04 x86_64 with the following commands:

gcc test.cpp -I/usr/include/qt4/QtCore/  -I/usr/include/qt4/QtGui/ -I/usr/include/qt4/QtWebKit  -I/usr/include/qt4/ -lQtCore -lQtGui -lQtWebKit -o test.out
gcc test2.cpp -I/usr/include/qt4/QtCore/  -I/usr/include/qt4/QtGui/ -I/usr/include/qt4/QtWebKit  -I/usr/include/qt4/ -lQtCore -lQtGui -lQtWebKit -o test2.out

to run the code, first do ./test2.out it should output a window ID, then do ./test.out <winid> where is the window id that is from the test2.out output

If you don't have a compositing window manager running, you may have to start xcompmgr

Instead of getting the result that I want, I just get a black square where the background of the other application should show through....

To demonstrate that translucency works in non embedding situations, just set EMBEDDING to 0 test.cpp

Please let me know if I am missing something or if there is a workaround.

Thanks

PS. I don't really know C/C++, I just ported my PySide problem case over for the benefit of this post. However, I should be able to Port any C/C++ recommendations back to PySide

2
  • It has been suggested on the QT mailing list, that may be a compositing issue. I have looked at the code for xcompmgr, and it seems to refuse to do composite rendering for windows that do not have the root window as a parent. I also tried compiz, but I wasn't able to get it to do any compositing... Oct 16, 2013 at 0:00
  • 1
    Normal compositing manager deal with top-level windows only. You need to do your own compositing. Oct 18, 2013 at 5:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.