Embedding Qwidget into X11 window using X11 programming

  • Hi This is the program that i used from the net to embed a Qwidget into a x11 window.I am unable to see the Widget. Can anyone help me with it.
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <QApplication>
    #include "mywidget.h"

    #include <X11/Xlib.h>

    QWidget* createWid(Display* d, Window w)
    MyWidget* widget = new MyWidget(0);

                         QApplication::translate("toplevel", "Top-level widget"));
                widget->move( 50, 50 );

    widget->setFixedSize(100, 100);
    XReparentWindow(d, widget->winId(), w, widget->x(), widget->y());


    return widget;

    int main(int argc, char* argvp[])
    Display *displayX;
    Window window;
    XEvent event;
    char *msg = "Hello, World!";
    int screen;

    QApplication qapp(argc, argvp);

    displayX = XOpenDisplay(NULL);
    if (displayX == NULL) {
    fprintf(stderr, "Cannot open display\n");

    screen= DefaultScreen(displayX);
    window = XCreateSimpleWindow(displayX, RootWindow(displayX, screen), 50, 50, 500, 500, 5, BlackPixel(displayX, screen), WhitePixel(displayX, screen));
    XSelectInput(displayX, window, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |KeyPressMask | KeyReleaseMask | ButtonPressMask
    | ButtonReleaseMask
    | KeymapStateMask | ButtonMotionMask | PointerMotionMask
    | FocusChangeMask
    | ExposureMask | StructureNotifyMask
    | SubstructureNotifyMask | PropertyChangeMask);

    XMapWindow(displayX, window);
    QWidget* wid ;
    wid= createWid(displayX, window);

    while (1) {
    XEvent event;
    XNextEvent(displayX, &event);
    if(wid != 0) {
    fprintf(stderr, "QT widget");

    return 0;


  • Hi was able to get the outer frame of the widget. solved by adding XMapRaised.
    But button not visible. Please let me know about the additions in the code

  • @sruthihsr: Please can you tell where do you insert XMapRaised ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.