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 embed Ogre3d in qt5 as a widget
Forum Update on Monday, May 27th 2025

How to embed Ogre3d in qt5 as a widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.11qwidgetogre
6 Posts 4 Posters 980 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.
  • timob256T Offline
    timob256T Offline
    timob256
    wrote on last edited by
    #1

    I started the starter project in qt5.11, but I can't show everything in one window.

    this moment i have two windows :(

    Screenshot_20211208_163950.png

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include <QGridLayout>
    #include "QTOgreWindow.h"
    #include "SdkQtCameraMan.h"
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = 0);
        ~Widget();
    
    protected:
        QGridLayout* gl_layaout;
    };
    
    #endif // WIDGET_H
    
    
    #include "widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        gl_layaout = new QGridLayout(parent);
        QTOgreWindow * ogreWindow = new QTOgreWindow ();
        ogreWindow->show();
    
        QWidget *container = QWidget::createWindowContainer(ogreWindow);
        gl_layaout->addWidget(container);
    
        this->setLayout(gl_layaout);
    
    }
    
    Widget::~Widget()
    {
    
    }
    

    what am I doing wrong ?? how to put an ogre in a QWidget right ??

    JonBJ 1 Reply Last reply
    0
    • timob256T timob256

      I started the starter project in qt5.11, but I can't show everything in one window.

      this moment i have two windows :(

      Screenshot_20211208_163950.png

      #ifndef WIDGET_H
      #define WIDGET_H
      
      #include <QWidget>
      #include <QGridLayout>
      #include "QTOgreWindow.h"
      #include "SdkQtCameraMan.h"
      
      class Widget : public QWidget
      {
          Q_OBJECT
      
      public:
          Widget(QWidget *parent = 0);
          ~Widget();
      
      protected:
          QGridLayout* gl_layaout;
      };
      
      #endif // WIDGET_H
      
      
      #include "widget.h"
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
      {
          gl_layaout = new QGridLayout(parent);
          QTOgreWindow * ogreWindow = new QTOgreWindow ();
          ogreWindow->show();
      
          QWidget *container = QWidget::createWindowContainer(ogreWindow);
          gl_layaout->addWidget(container);
      
          this->setLayout(gl_layaout);
      
      }
      
      Widget::~Widget()
      {
      
      }
      

      what am I doing wrong ?? how to put an ogre in a QWidget right ??

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @timob256 said in How to embed Ogre3d in qt5 as a widget:

      gl_layaout = new QGridLayout(parent);

      I know nothing about this Ogre stuff and its window, nor do you explain for people like me what exactly is wrong in your pic. But why are you using parent here? Shouldn't it be this?

      EDIT Oh, later you have this->setLayout(gl_layaout);, so maybe this won't matter after that? I would still change your current, just in case.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #3

        Show all of your code for the project. You are probably creating an instance of Widget to be separate window instead of adding it to the layout of your main window.

        1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I don't understand the problem - why do you suddenly use QWidget::createWindowContainer() again when you found a proper solution in your previous thread?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          timob256T 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            I don't understand the problem - why do you suddenly use QWidget::createWindowContainer() again when you found a proper solution in your previous thread?

            timob256T Offline
            timob256T Offline
            timob256
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            // Qwindow
            QTOgreWindow::QTOgreWindow(QWindow *parent)
                    : QWindow(parent)
                    , m_update_pending(false)
                    , m_animating(false)
                    , m_ogreRoot(NULL)
                    , m_ogreWindow(NULL)
                    , m_ogreCamera(NULL)
                    , m_cameraMan(NULL)
            {
                    setAnimating(true);
                    installEventFilter(this);
                    m_ogreBackground = Ogre::ColourValue(0.0f, 0.5f, 1.0f);
                    
                    // обявл элементы
                    gl_layaout[0] = new QGridLayout(parent);
                    gl_layaout[1] = new QGridLayout(parent);
                    gl_layaout[2] = new QGridLayout(parent);
                
                    gl_layaout[3] = new QGridLayout(parent);
                
                    l_label[0] = new QLabel(parent);
                    l_label[1] = new QLabel(parent);
                    l_label[2] = new QLabel(parent);
                
                    le_edit[0] = new QLineEdit(parent);
                    le_edit[1] = new QLineEdit(parent);
                    le_edit[2] = new QLineEdit(parent);
                    le_edit[3] = new QLineEdit(parent);
                    le_edit[4] = new QLineEdit(parent);
                    le_edit[5] = new QLineEdit(parent);
                    le_edit[6] = new QLineEdit(parent);
                
                    // настройки элеметов (стилизация)
                
                    // заполнение элементов
                    l_label[0]->setText("hla_global");
                    l_label[1]->setText("hla_local");
                    l_label[2]->setText("logger");
                
                    le_edit[0]->setText("server_ip_global");
                    le_edit[1]->setText("server_port_global");
                
                    le_edit[2]->setText("server_port_local");
                    le_edit[3]->setText("server_port_local");
                
                    le_edit[4]->setText("log");
                    le_edit[5]->setText("log_period_ms");
                    le_edit[6]->setText("log_size_in_mb");
                    
                
                    //разложение элементов по группам
                
                    gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1);
                    gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1);
                    gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1);
                
                    gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1);
                    gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1);
                    gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1);
                
                    gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1);
                
                
                    gl_layaout[3]->addLayout(gl_layaout[0], 0, 0, 1, 1);
                
                    si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                    gl_layaout[3]->addItem(si_spacer[0], 0, 1, 1, 1);
                
                    gl_layaout[3]->addLayout(gl_layaout[1], 0, 2, 1, 1);
                    si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                    gl_layaout[3]->addItem(si_spacer[1], 0, 3, 1, 1);
                    si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                    gl_layaout[3]->addItem(si_spacer[2],1, 0, 1, 1);
                    gl_layaout[3]->addLayout(gl_layaout[2], 2, 0, 1, 1);
                    si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                    gl_layaout[3]->addItem(si_spacer[3], 3, 0, 1, 1);
             
                    
                      this->setLayout(gl_layaout[3]);  // this not work !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
            }
            

            QWindows not unit setLayout ? install in element, not posible.

            @mchinand this code https://forum.qt.io/topic/132600/how-to-embed-ogre3d-in-qt5/9

            JonBJ 1 Reply Last reply
            0
            • timob256T timob256

              @Christian-Ehrlicher

              // Qwindow
              QTOgreWindow::QTOgreWindow(QWindow *parent)
                      : QWindow(parent)
                      , m_update_pending(false)
                      , m_animating(false)
                      , m_ogreRoot(NULL)
                      , m_ogreWindow(NULL)
                      , m_ogreCamera(NULL)
                      , m_cameraMan(NULL)
              {
                      setAnimating(true);
                      installEventFilter(this);
                      m_ogreBackground = Ogre::ColourValue(0.0f, 0.5f, 1.0f);
                      
                      // обявл элементы
                      gl_layaout[0] = new QGridLayout(parent);
                      gl_layaout[1] = new QGridLayout(parent);
                      gl_layaout[2] = new QGridLayout(parent);
                  
                      gl_layaout[3] = new QGridLayout(parent);
                  
                      l_label[0] = new QLabel(parent);
                      l_label[1] = new QLabel(parent);
                      l_label[2] = new QLabel(parent);
                  
                      le_edit[0] = new QLineEdit(parent);
                      le_edit[1] = new QLineEdit(parent);
                      le_edit[2] = new QLineEdit(parent);
                      le_edit[3] = new QLineEdit(parent);
                      le_edit[4] = new QLineEdit(parent);
                      le_edit[5] = new QLineEdit(parent);
                      le_edit[6] = new QLineEdit(parent);
                  
                      // настройки элеметов (стилизация)
                  
                      // заполнение элементов
                      l_label[0]->setText("hla_global");
                      l_label[1]->setText("hla_local");
                      l_label[2]->setText("logger");
                  
                      le_edit[0]->setText("server_ip_global");
                      le_edit[1]->setText("server_port_global");
                  
                      le_edit[2]->setText("server_port_local");
                      le_edit[3]->setText("server_port_local");
                  
                      le_edit[4]->setText("log");
                      le_edit[5]->setText("log_period_ms");
                      le_edit[6]->setText("log_size_in_mb");
                      
                  
                      //разложение элементов по группам
                  
                      gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1);
                      gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1);
                      gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1);
                  
                      gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1);
                      gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1);
                      gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1);
                  
                      gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1);
                      gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1);
                      gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1);
                      gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1);
                  
                  
                      gl_layaout[3]->addLayout(gl_layaout[0], 0, 0, 1, 1);
                  
                      si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                      gl_layaout[3]->addItem(si_spacer[0], 0, 1, 1, 1);
                  
                      gl_layaout[3]->addLayout(gl_layaout[1], 0, 2, 1, 1);
                      si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                      gl_layaout[3]->addItem(si_spacer[1], 0, 3, 1, 1);
                      si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                      gl_layaout[3]->addItem(si_spacer[2],1, 0, 1, 1);
                      gl_layaout[3]->addLayout(gl_layaout[2], 2, 0, 1, 1);
                      si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                      gl_layaout[3]->addItem(si_spacer[3], 3, 0, 1, 1);
               
                      
                        this->setLayout(gl_layaout[3]);  // this not work !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
              }
              

              QWindows not unit setLayout ? install in element, not posible.

              @mchinand this code https://forum.qt.io/topic/132600/how-to-embed-ogre3d-in-qt5/9

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @timob256 said in How to embed Ogre3d in qt5 as a widget:

              QWindows not unit setLayout ? install in element, not posible.

              Don't know what this means.

              this->setLayout(gl_layaout[3]); // this not work !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

              Don't know what this means.

              All your widgets are created with parent as their parent, instead of this. Since I wrote earlier

              But why are you using parent here? Shouldn't it be this?

              do you not think this applies to your case? Why?

              You are creating your widgets with a parent of parent of QTOgreWindow, and then this->setLayout(gl_layaout[3]); setting the layout on this. I don't get what you are trying to do or why.

              UPDATE
              I see you have now taken this question to https://forum.qt.io/topic/132674/how-do-i-put-a-qlayout-in-a-qwindow. It's always helpful to others if you cross-reference posts like this.

              I see now that my "But why are you using parent here? Shouldn't it be this?" is not applicable to QWindow. I will post into your other thread.

              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