PDA

View Full Version : put widget in layout



rimie23
26th May 2012, 23:32
Hi
if i create widget like that


class OgreWidget : public QWidget, public Ogre::FrameListener
{
Q_OBJECT
...................
}
OgreWidget *ogreWidget;
MainWindow::MainWindow()
{
ogreWidget = new OgreWidget(this);
setCentralWidget(ogreWidget);
...................................

how i can put this widget in layout
i make like that


QHBoxLayout* my_layout = new QHBoxLayout;
my_layout->addWidget(new QGroupBox("my scene"));
ogreWidget.setLayout(my_layout);


it dos not work it make to me error

ChrisW67
27th May 2012, 06:22
it dos not work it make to me error

Which bit does not work? How does it fail? What error? What effect are you trying to achieve?

You are trying to set a layout on the Ogre widget, which I guess has no method setLayout() and is not intended as a container. If you want to put the Ogre widget inside the layout with the group box then add it to the layout:


ogreWidget = new OgreWidget(this);

QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(new QGroupBox("My Scene", this));
layout->addWidget(ogreWidget);

QWidget *central = new QWidget(this);
central->setLayout(layout);
setCentralWidget(central);


If you wanted to put the Ogre widget inside the group box then it can be the central widget.


ogreWidget = new OgreWidget(this);

QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(ogreWidget);

QWidget *central = new QGroupBox("My Scene", this);
central->setLayout(layout);
setCentralWidget(central);

amleto
27th May 2012, 11:00
background reading... http://www.qtforum.org/post/119068/create-new-widget-with-signal.html#post119068

rimie23
28th May 2012, 07:53
Hi,thank you ChrisW67 it work
But
can we make manysublayout in "central"?


ogreWidget = new OgreWidget(this);

QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(ogreWidget);

QWidget *central = new QGroupBox("My Scene", this);
central->setLayout(layout);
setCentralWidget(central);

i will more explain
i create many viewport in my class " OgreWidget" like that


void OgreWidget::createViewports(void)
{
mWindow->addViewport(mCamera, 0, 0, 0, 0.5, 1); // large left half viewport
int columns = 3;
int rows = 4;
for(int y = 0; y < rows; y++)
for(int x = 0; x < columns; x++)
{
mWindow->addViewport(mCamera,
x + y * columns + 1, // each viewport needs a unique zorder value
0.5f + (0.5f / columns) * x, // left edge
(1.0f / rows) * y, // top edge
0.5f / columns, // tile width
1.0f / rows); // tile height
}
}

the result is like that
7759
and because i want make edge to each viewport
Amleto propose to use layout, gridlayout(thanks for him)
we make like that


ogreWidget = new OgreWidget(this);

QHBoxLayout* mainlayout = new QHBoxLayout;

QGridLayout* rightSide = new QGridLayout;

rightSide->addWidget(new QGroupBox("0,0"), 0, 0 );
rightSide->addWidget(new QGroupBox("0,1"), 0, 1 );
rightSide->addWidget(new QGroupBox("0,2"), 0, 2 );
rightSide->addWidget(new QGroupBox("1,0"), 1, 0 );
rightSide->addWidget(new QGroupBox("1,1"), 1, 1 );
rightSide->addWidget(new QGroupBox("1,2"), 1, 2 );
rightSide->addWidget(new QGroupBox("2,0"), 2, 0 );
rightSide->addWidget(new QGroupBox("2,1"), 2, 1 );
rightSide->addWidget(new QGroupBox("2,2"), 2, 2 );
rightSide->addWidget(new QGroupBox("3,0"), 3, 0 );
rightSide->addWidget(new QGroupBox("3,1"), 3, 1 );
rightSide->addWidget(new QGroupBox("3,2"), 3, 2 );


mainlayout->addWidget(ogreWidget);
QWidget *central = new QGroupBox("My Scene", this);
central->setLayout(mainlayout);
setCentralWidget(central);
mainlayout->addLayout(rightSide);

But the result is like that
7760
the problem did not resolved
i still see all the viewport in the same widget



is there an idea to find solution to the problem (just the idea)
is i must use signal //slot or what exactelly

because as i see i can"t make the small viewport in the other widget because all the viewport are in ogrewidget class and in this clss there is yhe function of paint ,............

All the idea and reply are wecome

ChrisW67
28th May 2012, 09:41
@amleto: Thanks for the backgrounder.

QGridLayout does not "divide my widget" in any way. It, and the other layout classes, arrange collections of separate widgets according to rules and the space available; see Layout Management

Here are your two options:

You have one Ogre widget with the internal viewports that it has and the limitations they come with.
You have 13 Ogre widgets sharing the same Ogre scene. One widget is the left half and the other 12 are in the grid. Put each Ogre widget inside the group boxes you already have. (Actually it could all be a single QGridLayout but you need to walk before running)


Either way, you should read Layout Management if you are going to use Qt.

Since I do not propose to learn Ogre I cannot tell you if option 2 is possible though I'd be very surprised if it were not.

Did I mention you should read Layout Management?

rimie23
28th May 2012, 09:56
Either way, you should read Layout Management if you are going to use Qt.
i will read it today, thanks for the advice
But

You have 13 Ogre widgets sharing the same Ogre scene. One widget is the left half and the other 12 are in the grid. Put each Ogre widget inside the group boxes you already have. (Actually it could all be a single QGridLayout but you need to walk before running)
i see that is not pratical choice , it's not fine to define 13 classes
i will learn about
to see how i applicate to obtain (because i still do not undertand your 1 st choice )

You have one Ogre widget with the internal viewports that it has and the limitations they come with.