Paint Errors and Crash Using QWidget :: createWindowContainer

In my Qt 5.3 application, I want to integrate the GUI from the child process into the main process window:

  • A child process creates a top-level QWidget .
  • The child process passes the WId widget as returned from QWidget::winId() parent (using IPC).
  • The parent uses QWindow::fromWinId() and QWidget::createWindowContainer() to create a QWidget for the graphical display of the child process. This widget is embedded in another widget layout.

remarks:

  • The child GUI is displayed but not displayed correctly: there are white borders that are not updated properly when recalibrating the parent.
  • If the size of the parent window is too small, the child process fails due to a violation of memory access in Qt code.
  • Unless I specify a parent with QWidget::createWindowContainer() to use a separate top-level window instead, it is built in just fine.
  • After the child opens a modal dialog box, for example QMessageBox , the problem will be fixed by itself, and then the child will be correctly implemented after the next resizing of the parent.

Especially the last moment puzzles me. I tried to find out if the QMessageBox several flags of the child widget, and if I can simulate these changes manually, to get around the problem without any luck.

Does anyone know what is going on here? What can a modal dialog do with widgets that fix the problem?

+6
source share
1 answer

First of all, thanks for this question. Until this time, I do not know about this function in Qt. I will spend some time realizing your solution and having the same problem: white frame.

After several tests, I try to update the window on the fly, and instead of white borders there are my own OS borders:

native borders after reparenting

It looks like when call QWidget::createWindowContainer Qt gets the size of the whole window, display a QWidget (with a smaller size than the whole window) and fill the background with white.

I found a solution for this problem: check the Qt::FramelessWindowHint window check box for the child widget before you call createWindowContainer in the parent window.

 this->setWindowFlags(Qt::FramelessWindowHint); 

I could not reproduce the crash problem after resizing. I add a child widget to the layout and it works great.

You can look at the source in the Git hub .

If this does not solve your failure problem, indicate the source of the problem.

NOTE: in the example on GitHub, I start a child project, read winId from the debug output, change the parent source and start the parent project.

+3
source

Source: https://habr.com/ru/post/986950/


All Articles