在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来布局,可以先新建一个窗口,在新建的窗口中使用Layout,然后再使用setCentralWi

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

290

被折叠的 条评论
为什么被折叠?



