How to embed Ogre3d in qt5 as a widget
-
I started the starter project in qt5.11, but I can't show everything in one window.
this moment i have two windows :(
#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 ??
-
@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 bethis
?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. -
I don't understand the problem - why do you suddenly use QWidget::createWindowContainer() again when you found a proper solution in your previous thread?
-
// 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
-
@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 ofthis
. Since I wrote earlierBut why are you using
parent
here? Shouldn't it bethis
?do you not think this applies to your case? Why?
You are creating your widgets with a parent of
parent
ofQTOgreWindow
, and thenthis->setLayout(gl_layaout[3]);
setting the layout onthis
. 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 bethis
?" is not applicable toQWindow
. I will post into your other thread.