Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Embedding Qwidget into X11 window using X11 programming
Forum Updated to NodeBB v4.3 + New Features

Embedding Qwidget into X11 window using X11 programming

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sruthihsr
    wrote on 13 Oct 2011, 06:25 last edited by
    #1

    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);
    if(widget)
    {
    widget->setWindowFlags(Qt::FramelessWindowHint);

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

    widget->setFixedSize(100, 100);
    widget->show();
    widget->setFocus();
    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");
    exit(1);
    }

    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");
    qapp.x11ProcessEvent(&event);
    }
    }

    XCloseDisplay(displayX);
    return 0;
    }

    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sruthihsr
      wrote on 14 Oct 2011, 13:42 last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        menjaraz
        wrote on 15 Apr 2012, 10:27 last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved