添加画布相关的代码,对main.cpp添加以下的代码:
main.cpp #include <Qt3DWindow> #include <QForwardRenderer> #include <QScreen> #include <QHBoxLayout> #include <QVBoxLayout> int main() { Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x81fdff))); //创建画布 QWidget *container = QWidget::createWindowContainer(view); QSize screenSize = view->screen()->size(); container->setMinimumSize(QSize(200, 100)); container->setMaximumSize(screenSize); //创建画布的容器,并将画布作为参数放进容器 QWidget *container = QWidget::createWindowContainer(view); QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); vLayout->setAlignment(Qt::AlignTop); hLayout->addWidget(container, 1); hLayout->addLayout(vLayout); //将画布的容器container放到窗口对象widget中,并添加布局 //至此 画布添加完毕 }
省略掉了上一篇中已经存在的代码,运行效果如下