addWidget in qWidgetStack
Hi,
I need to add a widget on a widgetstack (and work!) but I need it is 1/2 of widgetStack (insert from Designer)
Code:
MyWidget top (&w, "top");
top.
setGeometry(QRect(0,
0,w.
WidgetStack->width
()/2,w.
WidgetStack->height
()) );
int shared_top= w.WidgetStack->addWidget(&top);
cout << w.WidgetStack->width() << endl;
cout << w.WidgetStack->height() << endl;
Why doesn't it work? (cout print 101 and 31 (why 31? Should be much more))
Thanks....
Re: addWidget in qWidgetStack
It won't work this way. The widget always occupies the whole widget stack geometry. You have to use layouts, spacers, sizeHints and sizePolicies to alter the behaviour.
Re: addWidget in qWidgetStack
yes thanks. I try this way but layout don't appear on myWidgetstack..
Code:
MyWidget top (&w, "top shared", w.myWidget1);
layout->addWidget(&top);
I need to take w parent of top.
Re: addWidget in qWidgetStack
Layout needs to be assigned to a widget. Something like this:
Code:
//...
l->addWidget(chld);
//...
w->setLayout(l);
//...
stackedWidget->addWidget(w);
Re: addWidget in qWidgetStack
Sorry but my 'w' is: MainForm w;
Quote:
Originally Posted by wysota
Code:
l->addWidget(chld);
w->setLayout(l);
stackedWidget->addWidget(w);
In anyway, your code get this error:
Code:
error C2248: 'QWidget::setLayout' : cannot access private member declared in class 'QWidget'
I am in main.cpp...
Re: addWidget in qWidgetStack
Quote:
Originally Posted by mickey
I am in main.cpp...
This should not be done there :) Setting layouts should be done in the constructor of a widget. Nevertheless QWidget::setLayout() is public... Aa... you're using Qt3. Then setting the widget as a parent to a layout should be enough.
Re: addWidget in qWidgetStack
Sory your code don't compile, maybe bacause my widget is a QGLWidget and I put it in costructor of myGLWidget....
Code:
l->addWidget(chld);
//w->setLayout(l);
If I comment last istruction don't display.....
Re: addWidget in qWidgetStack
HI, this code seems ok. But it don't put 'l' on widget w. w->setlayout(l) don't compile.
Code:
l->addWidget(top);
//...........
this->WidgetStack->addWidget(w);
myGLWidget 'top appear in a small square on toolbar. I don't know how put it on widget w.
Any hints?