如何解决将在QtCreator中创建的自定义小部件添加到MainWindow
我希望在主窗口中显示使用Qt Creator单独创建的小部件。这是我到目前为止所做的。
- 为我的自定义窗口小部件添加了一个新的带有类的Qt表单。
- 在我的主窗口头文件中声明了新的小部件对象。
#include <QMainWindow>
#include "newcustomerwidget.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MoopsBilling; }
QT_END_NAMESPACE
class MoopsBilling : public QMainWindow
{
Q_OBJECT
public:
MoopsBilling(QWidget *parent = nullptr);
~MoopsBilling();
private:
Ui::MoopsBilling *ui;
NewCustomerWidget *newCustomerWidget; // this is the new widget
};
- 在主窗口构造函数中初始化我的自定义小部件。
MoopsBilling::MoopsBilling(QWidget *parent)
: QMainWindow(parent),ui(new Ui::MoopsBilling)
{
ui->setupUi(this);
newCustomerWidget = new NewCustomerWidget();
ui->centralwidget->layout()->addWidget(newCustomerWidget); // adding this to central widget gives me error (line 10)
}
-
试图将其添加到中央窗口小部件。有错误。
moopsbilling.cpp:10:错误:C2027:使用未定义类型'QLayout'
我希望将其他几个自定义窗口小部件添加到主窗口中,这将是分页表单的一部分。但是在这里,我陷入了错误,将它们添加到中央小部件中。
我希望有人可以提供指导,如何解决此问题以及如何在主表单中添加(和删除)自定义小部件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。