Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing errors and crash with QWidget::createWindowContainer

Tags:

c++

qt

qt5

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

  1. The child process creates a top-level QWidget.
  2. The child process communicates the widget's WId as returned from QWidget::winId() to the parent (using IPC).
  3. The parent uses QWindow::fromWinId() and QWidget::createWindowContainer() to create a QWidget displaying the child process' GUI. This widget is embedded into another widget's layout.

Observations:

  1. The child GUI is displayed but not rendered correctly: there are white borders that don't get updated properly when re-sizing the parent.
  2. If the parent window is resized too small, the child process crashes due to an memory access violation within Qt's code.
  3. If I don't specify a parent with QWidget::createWindowContainer() to use a separate top-level window instead, the child is embedded just fine.
  4. After the child opens a modal dialog, such as QMessageBox, the issue fixes itself, and the child is embedded correctly after the next resize of the parent.

Especially the last point puzzles me. I tried to find out if running the QMessageBox changes some flags on the child widget and if I can simulate these changes manually to work around the issue, without luck.

Does anyone have an idea what is happening here? What could the modal dialog possibly do to the widget that fixes the problem?

like image 712
Ferdinand Beyer Avatar asked May 11 '15 07:05

Ferdinand Beyer


1 Answers

First off all - thank you for this question. Before this time I am do not know about this feature in Qt. I spend some time to implement your solution and have the same problem: white border.

After few tests I try to do window reparenting on the fly and instead white borders there was native OS borders:

native borders after reparenting

It looks like when call QWidget::createWindowContainer Qt get size of entire window, display QWidget (with smaller size than entire window) and fill background with white color.

I found solution for this problem: set Qt::FramelessWindowHint window flag for child widget before you call createWindowContainer in parent window.

this->setWindowFlags(Qt::FramelessWindowHint);

I could not reproduce the problem with crash after resize. I add child widget to layout and it works fine.

You can look at my example source at Git Hub.

If it does not solve your problem with crash, please, provide some source for this issue.

NOTE: in example on GitHub i run child project, read winId from debug output, modify parent source and than run parent project.

like image 181
Andrei Shikalev Avatar answered Oct 31 '22 16:10

Andrei Shikalev