简体   繁体   English

将 QWidget 嵌入 X11 Window

[英]Embedding QWidget into X11 Window

I want to embed two QWidgets into a window created using XLib.我想将两个 QWidgets 嵌入到使用 XLib 创建的 window 中。 I have written this code:我写了这段代码:

// Assume all the necessary headers included

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

   // Create widget 1
   QWidget widget1 ; 
   widget1.setGeometry(44,44,666,666);
   widget1.show();

   // Create widget 2   
   QWidget widget2 ;
   widget2.setGeometry(144,144,666,666);
   widget2.show();      

   Display *display = XOpenDisplay( 0 ); // 0 parameter for default values

   if ( display != NULL )
   {
      // Create the x11 window using XLib
      Window w = XCreateWindow(display, DefaultRootWindow(display), 
      0, 0, 1200, 1100, 0,CopyFromParent, CopyFromParent, CopyFromParent, 0, 0);

      XMapWindow(display, w);
      XFlush(display);

      XReparentWindow(display, widget1.winId(), w, 0, 0);
      XReparentWindow(display, widget2.winId(), w, 1, 10);
  }

  else
      std::cout << "Error: Opening display" << std::endl ;

      return app.exec();
}

I am able to run this program successfully but these widgets are not getting embedded into the X11 window I created.我能够成功运行这个程序,但这些小部件没有嵌入到我创建的 X11 window 中。 All three things are getting created, but independently.这三样东西都被创造出来了,但是是独立的。 These widgets are not getting embedded into the window.这些小部件没有嵌入到 window 中。

the following would indicate that perhaps you need to think about the order of displaying the widgets so that the winId for your widgets gets set to something that can be passed to XReparentWindow.以下内容表明您可能需要考虑显示小部件的顺序,以便将小部件的 winId 设置为可以传递给 XReparentWindow 的内容。

http://www.qtforum.org/article/16529/xreparent-external-x11-application.html http://www.qtforum.org/article/16529/xreparent-external-x11-application.html

As alternate solution, you can to use QX11EmbedWidget instead QWidget in qt application and XEmbed protocol in XLib application, such as doing this QX11EmbedContainer .作为替代解决方案,您可以在 qt 应用程序中使用QX11EmbedWidget而不是 QWidget,在 XLib 应用程序中使用 XEmbed 协议,例如执行此QX11EmbedContainer This solution has a plus: you can realise different window in different processes.这个方案有个好处:可以在不同的进程中实现不同的window。

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

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