Embedding QWidget into X11 Window
Asked Answered
C

2

8

I want to embed two QWidgets into a window created using XLib. 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. All three things are getting created, but independently. These widgets are not getting embedded into the window.

Crazy answered 10/4, 2012 at 13:1 Comment(5)
Chek this out: QX11EmbedWidgetEnucleate
QX11EmbedWidgetCheckerboard
I have had used QX11 container to do the same. But I need to do it using the window created specifically using XLib, and hence the question.Crazy
@AmitTomar what's the header file for QX11 container? Or do I have to download an add-on for it?Taoism
@PrakharMohanSrivastava This class was supported in Qt 4.7 and Qt 4.8. In Qt 5.0 it isn't present, as far as I know.Crazy
A
5

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 .

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

Ashur answered 13/4, 2012 at 18:59 Comment(3)
I think what you are asking me to do is what I am already doing ? Anyways I tried other way round by calling show() for the 2 widgets after re-parenting had been done, but of no effect.Crazy
Well, rearranging the re-parenting before flushing and displaying the X11 window actually worked :-) Thanks a lot. And there goes the bounty.Crazy
@AmitTomar: Could you please provide a full-working example? It doesn't work for me.Mitis
B
2

As alternate solution, you can to use QX11EmbedWidget instead QWidget in qt application and XEmbed protocol in XLib application, such as doing this QX11EmbedContainer. This solution has a plus: you can realise different window in different processes.

Bradlybradman answered 19/1, 2013 at 23:55 Comment(1)
Though, this only works for Qt4, not for Qt5, right? Please explain otherwise.Mitis

© 2022 - 2024 — McMap. All rights reserved.