QWidget :: errore setLayout: Tentativo di impostare QLayout [...], che ha già un layout

StackOverflow https://stackoverflow.com/questions/3850252

  •  27-09-2019
  •  | 
  •  

Domanda

In fase di esecuzione (nessun errore di compilazione) ottengo sulla console

  

QWidget :: setLayout: Tentativo di impostare QLayout "" su CGSearchResult "",   che ha già un layout

Sto usando il seguente codice:

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);


}
È stato utile?

Soluzione

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

  

Se già esiste un gestore di layout installato su questo widget, QWidget sarà non lasciare che si installa un altro. È necessario innanzitutto eliminare il gestore di layout esistente (restituito da layout ()) prima di poter chiamare setLayout () con il nuovo layout.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top