PDA

View Full Version : QWidget on WidgetStack



mickey
6th March 2006, 14:49
HI,
i have designed a WidgetStack (with qtDesigner) with two page and I assinged them a name: page1 and page2 (this pages are QWidget, from desinger 'object explorer' I see this) .
I'd like to do this:


[code]QHBoxLayout *l = new QHBoxLayout(this->Page1);
l->addWidget(myWidget3,0,0);
this->WidgetStack->raiseWidget(Page1);

This don't work and MultipleView appear blank and mywidget3 appear in a small square on toolbar! Page2 is visible but I have insert on it a mywidget from designer...
Why this?

This below works but I'd like make different...

WidgetStack->raiseWidget( myWidget3 );
Thanks

Mad Max
7th March 2006, 05:13
Just use the addWidget method. There is not need to create any layouts.

WidgetStack->addWidget(myWidget3, num);

mickey
7th March 2006, 17:59
Sorry, but I need a layout....

mickey
8th March 2006, 00:47
...and I have also 2 widget in WidgetStack: page1 and page2; I'd like put a Hlayout on my page1 (QWidget create form designer) and insert inside Hlayout myWidget3....
Any hints? I tried to put somthing on page1 (also only mywidget3) but without result....
Any hints?

mickey
8th March 2006, 23:48
Hi, I tried this but don't compile.
I haven't still find a way to add a layoyut on 'MultupleView' (a page of a WidgetStack inserted from qtDesigner)


//myMainForm constructor
l = new QHBoxLayout(MultipleView);
l->addWidget(myWidget3,0,0);
MultipleView->setLayout(l);
l->setAutoAdd(TRUE);
WidgetStack->raiseWidget(MultipleView);



mymainform.cpp(48): error C2248: 'QWidget::setLayout' : cannot access private member declared in class 'QWidget'
Any hints? Thank you..

Mad Max
9th March 2006, 04:35
Hi, I tried this but don't compile.
I haven't still find a way to add a layoyut on 'MultupleView' (a page of a WidgetStack inserted from qtDesigner)


//myMainForm constructor
l = new QHBoxLayout(MultipleView);
l->addWidget(myWidget3,0,0);
MultipleView->setLayout(l);
l->setAutoAdd(TRUE);
WidgetStack->raiseWidget(MultipleView);



mymainform.cpp(48): error C2248: 'QWidget::setLayout' : cannot access private member declared in class 'QWidget'
Any hints? Thank you..

For some reason QWidgetStack the pagination begin with index 1
Try like this:


WidgetStack->addWidget(myWidget2);
WidgetStack->addWidget(myWidget3);
WidgetStack->raiseWidget(1);

There is no need to create layouts in any case :)

mickey
9th March 2006, 12:02
With your code, pagestack 1 appear empty, in the same way using raiseWidget(MultipleView); it works only with raiseWidget(myWidget2) but it isn't what I want...

I created a stack widget from designer; in page called MultipleView I must put on 2 widget, widget1 and 2; for this do I need layout!? Furthermore, I need call this page with
WidgetStack->raiseWidget(MultipleView); (this was how works before I toggled widget1 and widget2 on MultipleView (I toggled it from designer and now I'd like put they from MainForm...). Is it possible? Thanks

Mad Max
9th March 2006, 13:04
Sorry, I've slightly not understood what you want. I've created 2 widget in designer (Form1 and Form2) and placed they to QWidgetStack. Also, I've created an joint widget (Form1 + Form2) and placed it to QWidgetStack also:


int main( int argc, char ** argv )
{
QApplication a( argc, argv );
FormMain w;

w.widgetStack1->addWidget(new Form1(&w));
w.widgetStack1->addWidget(new Form2(&w));

QWidget * MultiView = new QWidget(&w);
QHBoxLayout * lo = new QHBoxLayout(MultiView);
lo->addWidget(new Form1(MultiView));
lo->addWidget(new Form2(MultiView));

w.widgetStack1->addWidget(MultiView);

w.show();
w.widgetStack1->raiseWidget(MultiView);

a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}

It does work ok. Is it that which necessary for you?

mickey
9th March 2006, 18:48
Maybe...I'm using widgetstack and Widget create from designer......
I insert and show my widget on MultipleView QWidget finally but I'm far to my taget. My new situation is this:


myWidget2 = new MyWidget(MultipleView, "myWidget2", MainForm::myWidget1);
myWidget3 = new MyWidget(MultipleView, "myWidget3", MainForm::myWidget1);
myWidget2->setGeometry(0,0, 300, 300);
myWidget2->setGeometry(300,0, 300, 300);
WidgetStack->raiseWidget(MultipleView);

This above works: I'd like to set geometry Maximum space available (half for each widget....but I don't know how...)
Furthermore, I think is better they in a QHLayout...but I don't know how.....Do you understand? thanks