为什么不能将QGridLayout添加到QMainWindow? [英] Why can't I add a QGridLayout to a QMainWindow?

查看:63
本文介绍了为什么不能将QGridLayout添加到QMainWindow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 QMainWindow 类.我为主布局编写了 QGridLayout ,但是每当我添加 setLayout(grid); 时,都会出现此错误:

I've created a QMainWindow class. I coded a QGridLayout for the main layout, but whenever I add 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.

我正在使用Qt Creator和Linux(ubuntu 12.10).

I'm using Qt Creator and using Linux (ubuntu 12.10).

推荐答案

您可以做的是创建一个QWidget,将其设置为中央窗口小部件,并为其进行布局.QMainWindow已经有它自己的布局来放置状态栏和主菜单,因此您不能直接设置另一个.

What you can do is create a QWidget set it as the central widget and give this one a layout. QMainWindow has its own layout already to place statusbar and mainmenu thus you can't set another one directly.

这篇关于为什么不能将QGridLayout添加到QMainWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆