简体   繁体   English

X11窗口未放入QWidget中以嵌入到Qt应用程序中

[英]X11 window does not put into QWidget for embedding in a Qt application

There is a Qt application. 有一个Qt应用程序。 GL-window created into this application by calling XCreateWindow function and I can't edit it. 通过调用XCreateWindow函数在此应用程序中创建的GL窗口,我无法对其进行编辑。 I need put Xwindow in QWidget inside my Qt applications. 我需要将Xwindow放在Qt应用程序内的QWidget中。

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. 如果窗口为0,则创建一个新的窗口小部件窗口,否则将窗口小部件的窗口设置为window。初始化窗口时,设置窗口的几何形状等)(如果initializeWindow为true)。 If initializeWindow is false, no initialization is performed. 如果initializeWindow为false,则不执行初始化。 This parameter only makes sense if window is a valid window. 仅当window是有效窗口时,此参数才有意义。

... ...

For verifying the result of function QWidget::create there is the following code: 为了验证函数QWidget :: create的结果,有以下代码:

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? 如何将X11窗口放入QWidget?

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). 通过窗口小部件解决问题的方法ParentWindow失败-xwindow嵌入在QWidget中,但是在调整窗口大小和关闭窗口时存在问题(它不会关闭)。

QX11EmbedContainer可能就是您所需要的。

Let Qt create your Window and then use the Qt X11 Drawable with your X11/GL code. 让Qt创建您的Window,然后将Qt X11 Drawable与X11 / GL代码一起使用。

With OpenGL and Qt you must use the Qt OpenGL context, if Qt is rendering using OpenGL. 如果Qt是使用OpenGL渲染的,则在OpenGL和Qt中必须使用Qt OpenGL上下文。 Just be aware that Qt expects the OpenGL state to be put back to what it was when it last used it. 请注意,Qt希望OpenGL状态恢复到上次使用时的状态。

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). 您可以使用QX11Info访问Drawable(也请检查Compiler没有看到QX11Info,因为在Xt中包含X11时,这涵盖了一个常见问题)。

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. Qt提供对X11和OpenGL的访问方式似乎在主要版本和次要版本之间都发生了变化,因此您可能需要进行一些挖掘。

I know that the above works with Qt5.1 upto 5.5. 我知道以上适用于Qt5.1 5.5。 Qt5.6 has problems with this approach that I've not yet resolved. Qt5.6有这种方法的问题,我尚未解决。

You should not touch window IDs in your first Qt program. 您不应在第一个Qt程序中触摸窗口ID。 Window IDs are a low level concept and a Qt programmer normally needs them only to do something outside of the Qt framework. 窗口ID是一个低级的概念,Qt程序员通常只需要它们就可以在Qt框架之外进行操作。 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. 这里特别注意查看如何使一个小部件成为另一个小部件的子级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM