Important: Please read the Qt Code of Conduct -

X11 Reparenting does not work.

  • I am trying to Reparent some widgets using x11 programming, but the windows are openings separately.

    what i expect is green color window inside red color window.

    what am i doing wrong.


    using namespace std;
    #include <iostream>
    #include <QtWidgets>
    #include <X11/Xlib.h>

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

       XSetWindowAttributes    frame_attributes;
      QWidget widget1 ;
       Window w;
       Display *display = XOpenDisplay( 0 ); 
       int screen = DefaultScreen(display);
                 XSetWindowAttributes xswa;
                 xswa.background_pixel=BlackPixel(display, screen);
                 xswa.border_pixel=WhitePixel(display, screen);
          xswa.override_redirect = False;

    if ( display != NULL )
    w = XCreateWindow(display, DefaultRootWindow(display),
    0, 0, 50, 50, 0,0,InputOutput, DefaultVisual(display, screen), CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect, &xswa);

      XMapWindow(display, w);
      XReparentWindow(display, child->winId(),w, 0, 0);
      XReparentWindow(display,w, widget1.winId(), 0, 0);

    }else {
    std::cout << "Error: Opening display" << std::endl ;
    return app.exec();


  • Moderators

  • Line 36 : child is not a pointer.

  • [quote author="JKSH" date="1384238774"]Hi,

    See It's a bit old, but might still work[/quote]

    Thanks JKSH,

    I forgot that .

    I added

     @ XFlush(display);@

    after Reparenting, now windows are shown inside each other.

    but the problem is when i close the main window, the windows are getting closed, but the terminal does not show the promt.

    I am running application from terminal , do i need to destroy any windows on exit , if so where and which one to destroy.

Log in to reply