2010-07-19 4 views
3

Je veux rendre le contenu de la fenêtre dans QWidget (ou QPixmap) en utilisant XComposite et XRender. Le problème auquel je suis confronté est que je ne peux pas obtenir l'image rendue dans le QWidget. Le code ci-dessous a été écrit à l'aide du didacticiel suivant: http://ktown.kde.org/~fredrik/composite_howto.html L'ID de la fenêtre est codé en dur, de sorte qu'il peut y avoir n'importe quel autre ID de fenêtre utilisé. La fenêtre QWidget qui s'ouvre n'affiche pas le contenu de la fenêtre d'origine, mais affiche simplement le rectangle gris. La même chose est si j'utilise le QPixmap, il contient juste un rectangle noir et rien d'autre. La prise en charge de XRender est activée.Qt + XCompositeRender problème

Qu'est-ce qui me manque ici?

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

Répondre

0

On dirait que vous devez utiliser

app.setGraphicsSystem("native"); 

au lieu d'un système graphique par défaut raster avoir QPixmap tampon stocké.