QWidget的:: setLayout的错误:试图设置QLayout [...],它已经具备了布局

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

  •  27-09-2019
  •  | 
  •  

在执行(没有编译错误)我得到的控制台上

  

QWidget的:: setLayout的:尝试设置QLayout “” 上CGSearchResult “”,   已经具有布局

我使用以下代码:

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


}
有帮助吗?

解决方案

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

  

如果已经有安装了这个小部件布局管理器,QWidget的不会让你安装另一个。您必须首先删除现有的布局管理器(按布局()返回)后,才能调用的setLayout()的新布局。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top