Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLayout: Attempting to add QLayout ...
Forum Updated to NodeBB v4.3 + New Features

QLayout: Attempting to add QLayout ...

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 21.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #3

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


        Declaration of (Platform) independence.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          [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?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved