Qt中使用setLayout()函数时报错------Attempting to set QLayout "" on MainWindow "MainWindow",which already has

在Qt的MainWindow中使用setLayout()时出现错误:'Attempting to set QLayout "" on MainWindow "MainWindow",which already has one'. 文章解释了这是因为MainWindow已经有内置的布局,包括菜单栏、工具栏等。解决方法是创建新的QWidget,为它设置自定义的Layout,然后通过setCentralWidget()将新QWidget设为主窗口的中央部件。
摘要由CSDN通过智能技术生成

  在Qt的主窗口(MainWindow)中使用setLayout()函数时,运行时即会报如题所示的错误,这是什么原因呢,我使用“F1”瞅了瞅QMainWindow,发现了如下信息:

A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar. The layout has a center area that can be occupied by any kind of widget. You can see an image of the layout below.

       

大概意思就是说mainwindow的主框架里已经有了一个Layout了,这个Layout包括了菜单栏、工具栏、停驻窗口区、中心窗口区、底部状态栏五部分,对于dev们应该够用了,但是如果实在是要再使用Layout

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值