QWidget :: setLayout error: attempting to install QLayout [...], which already has a layout

When executed (without compilation) I get on the console

QWidget :: setLayout: Attempting to set QLayout "to CGSearchResult" ", which already has a layout

I am using the following code:

CGSearchResult::CGSearchResult(QWidget *parent) : QWidget(parent)
{

    initControls();
    SetTableContent();

}

void CGSearchResult::initControls()
{


   backButton = new QPushButton(tr("&Back"));
   connect(backButton, SIGNAL(clicked()), this, SLOT(showHome()));

   model=new QStandardItemModel();


         QWidget::setFont(QFont("Courier New", 8, QFont::Bold));

        searchTable = new QTableView(this);
        searchTable->showGrid();

        searchTable->resize(720,400);
        searchTable->horizontalHeader()->setDefaultSectionSize(170);
        searchTable->verticalHeader()->setDefaultSectionSize(50);
        searchTable->verticalHeader()->hide();
        searchTable->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
        searchTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


    QGridLayout *layout = new QGridLayout();
    layout->addWidget(backButton, 0, 0, 1, 1);
    layout->addWidget(searchTable, 2, 0, 1, 1);

    setLayout(layout);


}
+3
source share
1 answer

http://qt-project.org/doc/qt-4.8/qwidget.html#setLayout

If a layout manager is already installed in this widget, QWidget will not let you install another. You must first delete the existing layout manager (returned by layout ()) before you can call setLayout () with a new layout.

+6
source

Source: https://habr.com/ru/post/1767758/


All Articles