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);
            label->setPixmap(QPixmap::fromImage(img));
            layout->addWidget(label, row, column);
            label->setAlignment( Qt::AlignCenter );
            label->setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
    
        } // inner for
    } // outer for
    
    // camera panel
    ui->label_14->setLayout(layout);
    

    }
    @

    Any ideas?


  • Moderators

    QMainWindow has a pre-set layout. It's shown here: http://qt-project.org/doc/qt-4.8/QMainWindow.html#qt-main-window-framework

    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:
    QMainWindow
    centralWidget as QWidget
    QStackedWidget
    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.