Important: Please read the Qt Code of Conduct -

QLayout: Attempting to add QLayout ...

  • I have the following warning:
    QLayout: Attempting to add QLayout "" to MainWindow "MainWindow", which already has a layout

    I use no layout elsewhere...

    my code:
    void MainWindow::createVMGridView()
    QGridLayout* layout = new QGridLayout(this);
    QImage img(":/images/tunnel.png");

    for( int row = 0; row < 3; row++ )
        for( int column = 0; column < 3; column++)
            QLabel* label = new QLabel(this);
            layout->addWidget(label, row, column);
            label->setAlignment( Qt::AlignCenter );
            label->setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
        } // inner for
    } // outer for
    // camera panel


    Any ideas?

  • Moderators

    QMainWindow has a pre-set layout. It's shown here:

    You probably want to create a "central widget" for the QMainWindow, and add the layout to that widget

  • Add label to your lay out, and set layout for your Mainwindow.

  • [quote author="Rahul Das" date="1345201297"]Add label to your lay out, and set layout for your Mainwindow.[/quote]

    This is not clear for me....

    I have:
    centralWidget as QWidget
    page5 of QStackedWidget there is a Qframe
    on the QFrame I have THE QLabel (ui->label_14)

    What's wrong with the layout?

  • Nothing. The problematic line is <code>QGridLayout* layout = new QGridLayout(this)</code>, which constructs a layout passing <code>this</code> as parent, which, in further consequence, sets the so created layout for <code>this</code>, the QMainWindow instance, which already has a layout.

Log in to reply