简体   繁体   English

为什么我不能将 QGridLayout 添加到 QMainWindow?

[英]Why can't I add a QGridLayout to a QMainWindow?

I've created a QMainWindow class.我创建了一个QMainWindow类。 I coded a QGridLayout for the main layout, but whenever I add setLayout(grid);我为主布局编写了一个QGridLayout ,但是每当我添加setLayout(grid); this error comes up:出现此错误:

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

As far as I know, I haven't added any sort of layout in my code before.据我所知,我之前没有在代码中添加任何类型的布局。

I'm using Qt Creator and using Linux (ubuntu 12.10).我正在使用 Qt Creator 和 Linux(ubuntu 12.10)。

What you can do is create a QWidget set it as the central widget and give this one a layout.您可以做的是创建一个 QWidget 将其设置为中央小部件并为其提供布局。 QMainWindow has its own layout already to place statusbar and mainmenu thus you can't set another one directly. QMainWindow 已经有自己的布局来放置状态栏和主菜单,因此您不能直接设置另一个。

QMainWindow comes with its own layout, you can't set that directly. QMainWindow自带布局,不能直接设置。

You probably should be setting your layout on the central widget, or possibly not using a QMainWindow at all if you don't want its layout/features.可能应该在中央小部件上设置布局,或者如果您不想要它的布局/功能,则可能根本不使用QMainWindow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM