开发者

Qt + XCompositeRender problem

开发者 https://www.devze.com 2023-01-07 16:41 出处:网络
I want to render the contents of the window in to QWidget ( or QPixmap ) using XComposite and XRender.

I want 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 enab开发者_如何学JAVAled.

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 );
    widget.show();
    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();
}


Looks like you need to use

app.setGraphicsSystem("native"); 

instead of default raster graphic system to have QPixmap buffer be stored.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号