Important: Please read the Qt Code of Conduct -

Problem with position of widget created with QWidget::createWindowContainer.

  • Hi,

    I have main window where I have QWidget container named widget, It was created in QtCreator. That widget should be a parent of my other widget that I create using QWidget::createWindowContainer.


    void MainClass::createWidgetFromId(WId id)
    cWindow = QWindow::fromWinId(id); // QWindow* cWindow;
    cWidget = QWidget::createWindowContainer(cWindow); // QWidget* cWidget;


    That cWidget has position (0,0) (absolute position, in relation to the main window). It should have (0,0) position but in relation to its parent. Parent has position (0,20) in relation to the main window.
    Any idea what is causing that problem?

  • Hi,maybe it's too late to answer. Once i have also used createWindowContainer,and found the cWidget's position is (0,0). Finnaly I have found this linke -> stackoverflow. try


    and it is better to use QHBoxLayout to manager cWidget and this

    cWindow = QWindow::fromWinId(id);
    cWidget = QWidget::createWindowContainer(cWindow);
    QHBoxLayout *layout = new QHBoxLayout(this);

Log in to reply