PDA

View Full Version : addWidget in qWidgetStack



mickey
2nd March 2006, 21:21
Hi,
I need to add a widget on a widgetstack (and work!) but I need it is 1/2 of widgetStack (insert from Designer)

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....

wysota
2nd March 2006, 22:34
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.

mickey
3rd March 2006, 02:36
yes thanks. I try this way but layout don't appear on myWidgetstack..


MyWidget top (&w, "top shared", w.myWidget1);
QBoxLayout *layout = new QHBoxLayout(w.WidgetStack, 5, 0, "top" );
layout->addWidget(&top);
I need to take w parent of top.

wysota
3rd March 2006, 03:16
Layout needs to be assigned to a widget. Something like this:


QWidget *w = new QWidget(this);
QHBoxLayout *l = new QHBoxLayout();
//...
QWidget *chld = new QWidget(this);
l->addWidget(chld);
//...
w->setLayout(l);
//...
stackedWidget->addWidget(w);

mickey
3rd March 2006, 12:41
Sorry but my 'w' is: MainForm w;



QWidget *w = new QWidget(this);
QHBoxLayout *l = new QHBoxLayout();
QWidget *chld = new QWidget(this);
l->addWidget(chld);
w->setLayout(l);
stackedWidget->addWidget(w);
In anyway, your code get this error:

error C2248: 'QWidget::setLayout' : cannot access private member declared in class 'QWidget'
I am in main.cpp...

wysota
3rd March 2006, 13:16
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.

mickey
3rd March 2006, 15:29
Sory your code don't compile, maybe bacause my widget is a QGLWidget and I put it in costructor of myGLWidget....


QWidget *w = new QWidget(this);
QHBoxLayout *l = new QHBoxLayout();
QWidget *chld = new QWidget(this);
l->addWidget(chld);
//w->setLayout(l);
If I comment last istruction don't display.....

mickey
3rd March 2006, 22:09
HI, this code seems ok. But it don't put 'l' on widget w. w->setlayout(l) don't compile.


QWidget *w = new QWidget;
QHBoxLayout *l = new QHBoxLayout(this);
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?