1

There is a Qt application. GL-window created into this application by calling XCreateWindow function and I can't edit it. I need put Xwindow in QWidget inside my Qt applications.

In the documentation:

void QWidget::create ( WId window = 0, bool initializeWindow = true, 
    bool destroyOldWindow = true ) [protected]

Creates a new widget window if the window is 0, otherwise sets the widget ' s window to window.Initializes the window sets the geometry etc.) if initializeWindow is true. If initializeWindow is false, no initialization is performed. This parameter only makes sense if window is a valid window.

...

For verifying the result of function QWidget::create there is the following code:

class ParentWindow : public QWidget
{
  Q_OBJECT

  public:
  ParentWindow(WId id)
  {
     create(id);
  }
};

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QPushButton* button = new QPushButton("MEGA BUTTON");
  button->show();
  ParentWindow w(button->winId());
  w.show();

  return a.exec();
}

When application start a single blank window appears. Although expected window containing a button (or to be a button). How can I put X11 window into my QWidget?

babutta
  • 11
  • 1
  • 2

4 Answers4

0

The problem was resolved:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Display* display = XOpenDisplay(NULL);

    XSynchronize(display, True);
    XSetErrorHandler(myErrorHandler);

    Window x11root = XDefaultRootWindow(display);

    int x = 500;
    int y = 500;
    unsigned int width = 150;
    unsigned int height = 150;
    unsigned int borderWidth = 0;
    long colorBlue = 0xff0000ff;

    Window x11w = XCreateSimpleWindow(display, x11root, x, y, 
        width, height, borderWidth, 1 /*magic number*/, colorBlue);

    QWidget w;
    w.resize(300, 300);
    w.show();

    XReparentWindow(display, x11w, w.winId(), 0, 0);
    XMapWindow(display, x11w); // must be performed after XReparentWindow, 
                               // otherwise the window is not visible.

    return a.exec();
}

To solve the problem through a widget ParentWindow failed - xwindow is embedded in QWidget, but have problems with resizing the window and closing it (it doesn't close).

babutta
  • 11
  • 1
  • 2
0

QX11EmbedContainer could be what you need.

sshilovsky
  • 958
  • 2
  • 9
  • 22
0

Let Qt create your Window and then use the Qt X11 Drawable with your X11/GL code.

With OpenGL and Qt you must use the Qt OpenGL context, if Qt is rendering using OpenGL. Just be aware that Qt expects the OpenGL state to be put back to what it was when it last used it.

You can get access to the Drawable using QX11Info (also check Compiler does not see QX11Info as this covers a common problem when including X11 with Qt).

The way Qt provides access to both X11 and OpenGL seems to change between major and minor versions so you may need to do a little bit of digging.

I know that the above works with Qt5.1 upto 5.5. Qt5.6 has problems with this approach that I've not yet resolved.

Community
  • 1
  • 1
Damian Dixon
  • 889
  • 8
  • 21
-1

You should not touch window IDs in your first Qt program. Window IDs are a low level concept and a Qt programmer normally needs them only to do something outside of the Qt framework. Managing widgets as children of other widgets is not that kind of task.

I recommend you start with one of the tutorials. Look in particular here to see how you make a widget a child of another widget.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • Thanks, but the matter is that I need x-window embedded in a QWidget. This is exactly my question. – babutta May 27 '13 at 08:08
  • Your explanations are confusing. You seemingly want to create a Qt widget and place a Qt pushbutton inside it, then you want to do something else. It is not clear what exactly. Do you want to reparent an existing toplevel X11 window and make it a a child of a new Qt widget window? – n. m. could be an AI May 27 '13 at 10:36
  • Yes, I want to do it. Excuse me for vague explanation. My English is not good enough =) – babutta May 29 '13 at 05:24