December 15, 2010

maciek maciek
Lab Rat
67 posts

QStackedWidget vs. QStackedLayout

 

Hi,
I need to have in my app area which changes while user interaction and both of these classes seem to be solution to my problem. I’ve read documentation of both and it’s very similar. So what are main differences? Is any of them obsolete/depreciated (as with *widget and *views)?

 Signature 

Earth is a beta site.

5 replies

December 15, 2010

anselmolsm anselmolsm
Ant Farmer
417 posts

QStackedWidget is a convenience class built on top of QStackedLayout. The main difference is that QStackedWidget inherits QWidget (through QFrame), while QStackedLayout does not. Summing up, QStackedWidget can be used as a toplevel widget, while QStackedLayout have to be put in a QWidget.

 Signature 

Anselmo L. S. Melo (anselmolsm)
www.anselmolsm.org

December 15, 2010

peppe peppe
Ant Farmer
1025 posts

The former is a widget, the latter is a layout. The widget itself is a simple convenience QWidget using QStackedLayout and exposing its API. Use the one that best fits your requirements. End of the story :)

BTW, *widget and *views are not deprecated at all, they just cover different use cases.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

December 15, 2010

QtK QtK
Lab Rat
1140 posts

And the document has this

QStackedWidget is a convenience layout widget built on top of the QStackedLayout class.

Edit Did’t refresh the page and so missed the above replies.

December 15, 2010

maciek maciek
Lab Rat
67 posts

OK, thanks for your answers – layout will do the work for me.

peppe: according to some documentation [doc.qt.nokia.com] it seems that widgets stays to be “compatible” with Qt3.

“These classes are less flexible than the view classes, and cannot be used with arbitrary models. We recommend that you use a model/view approach to handling data in item views unless you strongly need an item-based set of classes.”

 Signature 

Earth is a beta site.

December 15, 2010

peppe peppe
Ant Farmer
1025 posts

maciek wrote:
OK, thanks for your answers – layout will do the work for me.

peppe: according to some documentation [doc.qt.nokia.com] it seems that widgets stays to be “compatible” with Qt3.

“These classes are less flexible than the view classes, and cannot be used with arbitrary models. We recommend that you use a model/view approach to handling data in item views unless you strongly need an item-based set of classes.”

Their API is similar, sure, but this doesn’t make them outdated or deprecated. They have their (very limited and specific) use case, that’s it :)

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

 
  ‹‹ [SOLVED] manipulating qmainwindow widget through qdialog      Timeline widget ››

You must log in to post a reply. Not a member yet? Register here!