View Full Version : Qt + XRenderComposite

20th July 2010, 10:23
Hi all.

I am trying to render the contents of the window in to QWidget or QPixmap using XComposite and XRender. The Issue I'm facing is that I can't get the picture be rendered in the QWidget. The code below has been written using the following tutorial: http://ktown.kde.org/~fredrik/composite_howto.html The window ID is hardcoded, so there can be any other window ID used. QWidget window which opens does not display the contents of the original window, but just shows the blank gray rectangle. The same thing is if I use the QPixmap, it contains just black rectangle and nothing else. XRender support is enabled.

What I'm missing here ?

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

QApplication app( argc, argv );

Display *dpy = XOpenDisplay( getenv("DISPLAY") );

Window window = 2097154;

XCompositeRedirectWindow( dpy, window, CompositeRedirectManual );

XWindowAttributes attr;

XGetWindowAttributes( dpy, window, &attr );

XRenderPictFormat *format = XRenderFindVisualFormat( dpy, attr.visual );
bool hasAlpha = ( format->type == PictTypeDirect && format->direct.alphaMask );
int x = attr.x;
int y = attr.y;
int width = attr.width;
int height = attr.height;

qDebug() << hasAlpha << x << y << width << height;

XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors; // Don't clip child widgets

QWidget widget;
widget.setGeometry( 100, 100, 500, 500 );
Picture picture = XRenderCreatePicture( dpy, window, format, CPSubwindowMode, &pa );

XRenderComposite( dpy, PictOpSrc, picture, None,
widget.x11PictureHandle(), 0, 0, 0, 0, 0, 0, 500, 500 );

XRenderFreePicture( dpy, picture );

return app.exec();

I would be also grateful if someone could provide the sources of the qx11mirror class from Graphics-dojo ( http://labs.trolltech.com/page/Graphics/Examples/Examples2 ) As the SVN link doesn't seem to work

19th August 2010, 10:20
I wrote a demo, hope it help you.5088