PDA

View Full Version : layout in widget give me an empty window!



rimie23
3rd June 2012, 09:03
Hi,
i have Splitter and i make like that


QVBoxLayout *mVerticalLayout;
QSplitter *Splitter = new QSplitter(this);
Splitter->setOrientation(Qt::Vertical);
mVerticalLayout->addWidget(Splitter);

QRenderWindow *orw = new QRenderWindow(Splitter);
mQRenderWindowList.append(orw);
Splitter->addWidget(orw);

and that work very good
But i want now add name of each Splitter( i want to see the name) for that i change the method and i use qgroubbox
But that does not work
i make like that



QHBoxLayout *mVerticalLayout;
QWidget *central = new QGroupBox("My Scene", this);


QOgreRenderWindow *orw = new QOgreRenderWindow(central);

mVerticalLayout->addWidget(orw);
central->setLayout(mVerticalLayout);


But that make to me an empty window

rimie23
3rd June 2012, 13:43
i tried to make like that


QWidget *central = new QGroupBox("My Scene", this);


QRenderWindow *orw = new QRenderWindow();
mQOgreRenderWindowList.append(orw);

mVerticalLayout->addWidget(central);
mVerticalLayout->addWidget(orw);

i see the groupbox "my scene" in the left of window and the render window (orw) in the right of window
i can't make the orw in the groupbox

rimie23
3rd June 2012, 21:06
when i change this line

mVerticalLayout-> addWidget(central);
by this

central->setLayout(mVerticalLayout);

i see an empty window (there no groupbox, no scene)

amleto
3rd June 2012, 22:06
the rules are simple.

if a widget has a parent, it is shown in the parent.

if a layout is set on a widget, the widget is now the parent of all Widgets in the layout.

that is all you need to know.

ChrisW67
4th June 2012, 01:13
@Rimie: If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem, rather than assorted fragments. We ultimately have no idea what you have actually done because none of the fragments is complete and subsequent amendments depend on knowing where and to what you have applied them.

You may be better off using Qt Designer either standalone or inside Qt Creator. Either way, you must read Layout Management or you will waste a lot of time.

I am going to assume this is a continuation of your earlier posts of a similar flavour. Here is a complete example of two fake Ogre widgets in a splitter. The left widget in the splitter has a group box label, and the one on the right does not... so you can compare.


#include <QtGui>
#include <QDebug>

class FakeOgreWidget: public QLabel
{
public:
FakeOgreWidget(QWidget *p = 0): QLabel("Fake Ogre Widget", p) { }
};

class LabeledOgreWidget: public QGroupBox
{
public:
LabeledOgreWidget(const QString &label, QWidget *p = 0):
QGroupBox(label, p)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(new FakeOgreWidget(this));
setLayout(layout);
}
};


class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QSplitter *splitter = new QSplitter(this);
splitter->addWidget(new LabeledOgreWidget("Left", splitter));
splitter->addWidget(new FakeOgreWidget(splitter));

setCentralWidget(splitter);
}

private:
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow m;
m.resize(640, 480);
m.show();
return app.exec();
}
#include "main.moc"

rimie23
4th June 2012, 08:02
thank you for repling

If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem
i did not copy all the code because it have not relation of this problem (it is not in qt ) i know that because my program work very well when i just make that



void QWidget::setViewNum(int num)
{
if(num == 1)
{
QVBoxLayout *mVerticalLayout;
QSplitter *Splitter = new QSplitter(this);
Splitter->setOrientation(Qt::Vertical);
mVerticalLayout->addWidget(Splitter);

QRenderWindow *orw = new QRenderWindow(Splitter);
mQRenderWindowList.append(orw);
Splitter->addWidget(orw);
}
}

and QRenderWindow is like that

QRenderWindow::QRenderWindow(QWidget *parent) : QWidget(parent)
and in mainwindow i make like that


MainWindow::MainWindow()
{
mQWidget = new QWidget(this);
setCentralWidget(mQWidget);

all that work good i can see my object in the splitter

But when i want use groupbox that do not work (i see just an empty window, you can see my code in the firt or the second post )

I hope that what i write now it help you to see where is my problem exactelly

Jonny174
4th June 2012, 08:23
QWidget *central = new QGroupBox("My Scene", this);

QOgreRenderWindow *orw = new QOgreRenderWindow(central);

QHBoxLayout *mVerticalLayout = new QHBoxLayout(central);
mVerticalLayout->addWidget(orw);

rimie23
4th June 2012, 08:37
thanks Jonny
But it dos not work it still empty window

amleto
4th June 2012, 11:31
thank you for repling

If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem
i did not copy all the code because it have not relation of this problem (it is not in qt ) i know that because my program work very well when i just make that


you will note that he said 'self-contained complete program' - this DOES NOT have to be your whole program - it should be a self-contained complete program. Comprendes?


thanks Jonny
But it dos not work it still empty window


how about you post a self-contained complete program that doesnt work, and we will help with what is wrong.

I never trust anyone that says 'it doesn't work' when they have not shown us *what* doesnt work.

rimie23
4th June 2012, 11:53
"it should be a self-contained complete program."
do not you mean all the program ?
because as exemple "QOgreRenderWindow" containd many things have not relation with qt

Sory than what you mean by " self-contained complete program"

Edit : i work with ogre+qt , if you can integrate ogre i have not problem to give you version (code) that work with splitter and do not work when i add the groupbox (if i understand good the
" " self-contained complete program" that mean program where you can execute it and you can't execute it if you have not ogre)
else if it's just code where i have qt look

Qogrewidget have this member


#ifndef QOGREWIDGET_H
#define QOGREWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QSplitter>
#include <QList>

#include <OGRE/Ogre.h>

#include "QOgreRenderWindow.h"

class QOgreRenderWindow;
class QOgreWidget : public QWidget, public Ogre::FrameListener
{
Q_OBJECT

public:


QOgreWidget(QWidget *parent = 0);
~QOgreWidget();
Ogre::Root *mRoot;
QHBoxLayout *mVerticalLayout;

QList<QOgreRenderWindow*> getOgreWindows() { return mQOgreRenderWindowList; }
int nb_cam;
private:
Ogre::RenderWindow *mRenderWindow;
Ogre::SceneManager* mSceneMgr;


QList<QOgreRenderWindow*> mQOgreRenderWindowList;
int mainProcessID;
void init();
void initResources();
void createScene();
void timerEvent(QTimerEvent* evt);
protected:
virtual bool frameStarted(const Ogre::FrameEvent& evt);
virtual bool frameEnded(const Ogre::FrameEvent& evt);


virtual void showEvent(QShowEvent *evt);




public slots:

void setViewNum(int num);

private:
Ogre::Vector3 cPosition;
Ogre::Entity* ogreCube;
Ogre::SceneNode* CubeNode;
};

#endif // QOGREWIDGET_H





QOgreWidget::QOgreWidget(QWidget *parent) :
QWidget(parent),

mSceneMgr(NULL)
{

mRenderWindow = NULL;

mVerticalLayout = new QHBoxLayout(this);
}void QOgreWidget::setViewNum(int num)
{
for(int i = 0;i<mQOgreRenderWindowList.count();i++)
{
delete mQOgreRenderWindowList.takeAt(i);
i--;
}

for(int i = 0; i<mVerticalLayout->count();i++)
{
delete mVerticalLayout->takeAt(i);
i--;
}

if(num == 1)
{
/* QWidget *central = new QGroupBox("My Scene", this);



mQOgreRenderWindowList.append(orw);

mVerticalLayout->addWidget(central);
mVerticalLayout->addWidget(orw); */QOgreRenderWindow * orw = new QOgreRenderWindow(QString("View1"),mSceneMgr,mRoot,nb_cam/*,central*/);
mVerticalLayout->addWidget(orw);
QWidget *central = new QGroupBox("My Scene",orw);
// mVerticalLayout->addWidget(central);
central->setLayout(mVerticalLayout);
}

//////////////////////
all the code here has relation with ogre not with qt
///////////////////////
void QOgreWidget::setViewNum(int num)//It is slot
{

QSplitter *Splitter = new QSplitter(this);
Splitter->setOrientation(Qt::Vertical);
mVerticalLayout->addWidget(Splitter);

QRenderWindow *orw = new QRenderWindow(Splitter);
mQRenderWindowList.append(orw);
Splitter->addWidget(orw);
if(num == 4)
{

QSplitter *Splitter = new QSplitter(this);
Splitter->setOrientation(Qt::Vertical);
QSplitter *Splitter2 = new QSplitter(Splitter);
Splitter2->setOrientation(Qt::Horizontal);

Splitter->addWidget(Splitter2);

QSplitter *Splitter3 = new QSplitter(Splitter);
Splitter3->setOrientation(Qt::Horizontal);

Splitter->addWidget(Splitter3);

mVerticalLayout->addWidget(Splitter);

QOgreRenderWindow *orw = new QOgreRenderWindow(Splitter2);
mQOgreRenderWindowList.append(orw);
Splitter2->addWidget(orw);

orw = new QOgreRenderWindow(Splitter3);
mQOgreRenderWindowList.append(orw);
Splitter3->addWidget(orw);

orw = new QOgreRenderWindow(Splitter3);
mQOgreRenderWindowList.append(orw);
Splitter3->addWidget(orw);

orw = new QOgreRenderWindow(Splitter3);
mQOgreRenderWindowList.append(orw);
Splitter3->addWidget(orw);


}
}



the class QOGRERENDERWINDOW


#ifndef QOGRERENDERWINDOW_H
#define QOGRERENDERWINDOW_H

#include <QWidget>
#include <QPaintEngine>
#include <QPaintEvent>
#include <QResizeEvent>

#include <OGRE/Ogre.h>
#include "my_interface.h"

class QOgreRenderWindow : public QWidget
{
Q_OBJECT
public:


QOgreRenderWindow(QWidget *parent = 0);
~QOgreRenderWindow();



private:
QString mWindowName;
Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mRenderWindow;
Ogre::Camera *mCamera;
int nb_cam;
Ogre::Viewport* mVp;
Ogre::Root *mRoot;
void init();
void createOrbitalCamera();

protected:
virtual QPaintEngine* paintEngine() const { return 0; }
virtual void paintEvent(QPaintEvent* evt);
virtual void resizeEvent(QResizeEvent* evt);
virtual void keyPressEvent(QKeyEvent* evt);
virtual void keyReleaseEvent(QKeyEvent* evt);

virtual void mouseReleaseEvent(QMouseEvent* evt);

virtual void wheelEvent(QWheelEvent * evt);
};

#endif // QOGRERENDERWINDOW_H



on mainwindow


MainWindow::MainWindow()
{
mQOgreWidget = new QOgreWidget(this);

setCentralWidget(mQOgreWidget);
}
void MainWindow::setViewNum(int num)
{
mQOgreWidget->setViewNum(num);

}

in main


int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow window;
window.show();
window.setViewNum(1);
return app.exec();
}



that all my code that he has not relation with ogre (the rest is in ogre , c++) , that code with the code in ogre the result is an object in window (splitter ) or 4 view in each view i see my object
if i add groupbox(with the code in my first reply ) i do not see the object

I hope with this code i give you"self-contained complete program" (and i said to you i can give you version of my program with ogre)

amleto
4th June 2012, 18:06
self contained + complete - means you show ALL code from an EXAMPLE program that has the *same* problem. You do *not* need ogre to show any problem with widgets and layouts.

As nobody can copy + paste your code and make it compile (with suitable pro file), then no, your code is not complete. Ogre has nothing at all to do with a problem with a groupbox. Make your example much simpler without any ogre.

rimie23
4th June 2012, 22:18
Sorry for this question
But what i make in this " QOgreRenderWindow" ?
i have not idea what i make here if i do not use ogre

Added after 1 18 minutes:

finally i tried an exemple
77967797779877997800
you can download it when we run it it give to me an empty window
(you can see too that there is code in comment (that code contain the code with splitter that work))
i hope that will help (that is self contained + complete)

rimie23
4th June 2012, 23:09
is that what you want? or i can copy it her

amleto
4th June 2012, 23:34
just use a QLabel. Use anything that you want.


erm, yeah. You were pretty confused about what layout goes where.


this is probably what you meant:
qogrewidget.cpp


#include "QOgreWidget.h"
#include "qq.h"

QOgreWidget::QOgreWidget(QWidget *parent) :
QWidget(parent)
{

mVerticalLayout = new QHBoxLayout(this);

}
void QOgreWidget::setViewNum(int num)
{
if(num == 1)
{
QWidget *central = new QGroupBox("My Scene", this);

QLabel* orw = new QLabel("i am",central);

QHBoxLayout* Layout = new QHBoxLayout();
Layout->addWidget(orw);

central->setLayout(Layout);


mVerticalLayout->addWidget(central);
}
}

rimie23
4th June 2012, 23:47
But i make like that


QWidget *central = new QGroupBox("My Scene", this);


QLabel* orw = new QLabel("i am",central);

mVerticalLayout->addWidget(orw);
central->setLayout(mVerticalLayout);

the label is in the groupbox no?
and when i make like that

central->setLayout(mVerticalLayout);
that mean i make relation betwwen the groupbox and the "mVerticalLayout"

Added after 8 minutes:

thanks a lot

it's true when you simplify the problem you can find the solution

amleto
4th June 2012, 23:54
the label is in the groupbox after line4, but it is not in the groupbox after line 6, since you just added to the layout - now it is just in 'this' since 'this' owns the layout.

rimie23
5th June 2012, 09:36
hi

i have question out this

look what i see when i run my program
7801

the viewport and the window have not the same size
have you see this problem before?

amleto
5th June 2012, 10:55
you havent put it in layout properly.

There is no point in setting parents on widgets and hoping things work out in the end. Create the widgets with no parent, and add them to a suitable layout.

rimie23
5th June 2012, 13:23
Create the widgets with no parent, and add them to a suitable layout.
what widget ?


QWidget *central = new QGroupBox("My Scene", this);

QOgreRenderWindow * orw = new OgreRenderWindow(); //i delete the parent of this widget

QHBoxLayout* Layout = new QHBoxLayout();
Layout->addWidget(orw);

central->setLayout(Layout);


mVerticalLayout->addWidget(central);

But it still the same render

amleto
5th June 2012, 14:11
line 1 - you set parent
line 11 - you put the widget in a layout.


that makes setting the parent in line 1 pointless. And I believe that you get confused between the difference of being in a layout and merely having a parent.

rimie23
5th June 2012, 18:59
thanks for the advice
i resolve the problem