Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set ui->widget as Qt3DExtras::Qt3DWindow

How to set ui->widget as Qt3DExtras::Qt3DWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 477 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by sonichy
    #1
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <Qt3DCore/QEntity>
    #include <Qt3DExtras/QPhongMaterial>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        Qt3DCore::QEntity *rootEntity;
        Qt3DExtras::QPhongMaterial *material;
    
    private slots:
        void on_actionRender_triggered();
    
    };
    
    #endif // MAINWINDOW_H
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <Qt3DExtras/Qt3DWindow>
    #include <Qt3DExtras/QCuboidMesh>
    #include <Qt3DCore/QTransform>
    #include <Qt3DExtras/QForwardRenderer>
    #include <Qt3DRender/QCamera>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        Qt3DExtras::Qt3DWindow *window;
        Qt3DExtras::Qt3DWindow *window = new Qt3DExtras::Qt3DWindow();
        window->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d9f)));
        ui->widget = window; //here
        rootEntity = new Qt3DCore::QEntity;
        window->setRootEntity(rootEntity);
        window->show();
    
        // Material
        material = new Qt3DExtras::QPhongMaterial();
        material->setDiffuse(QColor(QRgb(0xbeb32b)));
    
        Qt3DRender::QCamera *cameraEntity = window->camera();
        cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cameraEntity->setPosition(QVector3D(0, 0, 20.0f));
        cameraEntity->setUpVector(QVector3D(0, 1, 0));
        cameraEntity->setViewCenter(QVector3D(0, 0, 0));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_actionRender_triggered()
    {
        Qt3DCore::QEntity *cuboidEntity = new Qt3DCore::QEntity(rootEntity);
        Qt3DExtras::QCuboidMesh *cuboidMesh = new Qt3DExtras::QCuboidMesh();
        cuboidMesh->setXExtent(3);
        cuboidMesh->setYExtent(2);
        cuboidMesh->setZExtent(4);
        Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform();
        cuboidTransform->setTranslation(QVector3D(1.0f, -1.0f, 1.0f));
        cuboidTransform->setRotationX(30);
        cuboidTransform->setRotationY(40);
        cuboidEntity->addComponent(cuboidMesh);
        cuboidEntity->addComponent(material);
        cuboidEntity->addComponent(cuboidTransform);
    }
    

    https://github.com/sonichy

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved