QWidget::setLayout 错误:尝试设置 QLayout [...],它已经有一个布局

发布于 2024-09-25 18:15:43 字数 1206 浏览 0 评论 0原文

执行时(没有编译错误)我进入控制台

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

我正在使用以下代码:

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


}

On execution (no compile error) I get on the console

QWidget::setLayout: Attempting to set QLayout "" on 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);


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪操控生活 2024-10-02 18:15:43

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

如果此小部件上已经安装了布局管理器,QWidget 将不允许您安装另一个布局管理器。您必须首先删除现有的布局管理器(由layout()返回),然后才能使用新布局调用setLayout()。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文