PDA

View Full Version : All widgets are visible in QStackedWidget



YuriyRusinov
20th March 2007, 18:49
Hello, All !

I have to process 4 different dialogs in QStackedWidget.
I do this


wsForm = new WsPropertiesForm (0, false, 0);
QSize cwSize (wsForm->maximumSize ());
rForm = new RasterPropertiesForm (false, 0);
dForm = new DocumentPropertiesForm (0, false, 0);
lForm = new LayerPropertiesForm (0, false, 0);
...
int wsIndex = this->ResultsStackedW->addWidget (wsForm);
int rIndex = this->ResultsStackedW->addWidget (rForm);
int dIndex = this->ResultsStackedW->addWidget (dForm);
int lIndex = this->ResultsStackedW->addWidget (lForm);
this->ResultsStackedW->setCurrentIndex (0);
...

In form constructor. When this form is shown, I see all these widgets simultaneously. Where is error ? I have to see these forms code ?

wysota
20th March 2007, 19:45
Can we see a screenshot?

YuriyRusinov
21st March 2007, 11:51
Oh, I'm sorry. Here it is

wysota
21st March 2007, 12:12
What happens if you substitute your form objects with for example QTextEdit?

high_flyer
21st March 2007, 12:17
Are you using QDialog as a base class for your forms?
This might be the problem then:


Note that QDialog (an any other widget that has type Qt::Dialog) uses the parent widget slightly differently from other classes in Qt. A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself). It will also share the parent's taskbar entry.

YuriyRusinov
21st March 2007, 12:18
All works fine.

wysota
21st March 2007, 12:20
Then the problem is probably in your forms implementations. Do you by any chance call show() on them somewhere?

YuriyRusinov
21st March 2007, 12:22
Are you using QDialog as a base class for your forms?
This might be the problem then:

You're right. Base class for these forms is QDialog, because they have to be used in two different modes, as modal form and widget on another form.

wysota
21st March 2007, 12:25
You're right. Base class for these forms is QDialog, because thea\y have to be used in two different modes, as modal form and widget on another form.

Implement them as widgets then and wrap into QDialog only when you need it.

YuriyRusinov
21st March 2007, 12:37
OK, What functions have to be reimplemented in order to transform form to dialog ?

wysota
21st March 2007, 12:54
All you need is this:

QDialog dlg;
QVBoxLayout *l = new QVBoxLayout(&dlg);
MyWidget *w = new MyWidget;
l->addWidget(w);
dlg.exec();

YuriyRusinov
21st March 2007, 14:18
Thanks a lot, problem was solved by similar method.


QWidget * cW = new QWidget ;
QVBoxLayout *lW = new QVBoxLayout (cW);
lW->addWidget (wForm);

YuriyRusinov
22nd March 2007, 09:47
I solved this problem. But I have one question. Because QDialog class inherits QWidget, can I set appropriate flags/properties for direct show in QStackedWidget (or QStackedLayout) ?

wysota
22nd March 2007, 10:34
QStackedLayout is not a widget so obviously you can't set any flags there. What do you mean by "direct show"?

YuriyRusinov
22nd March 2007, 12:02
I'm sorry. My question was can I set some flags and/or properties on my forms and make


stackedLayout->addWidget (form1);
...

to receive the same results ?