the basic idea of following code is to create a collection of widgets and add the collection to a scroll area,each collection has at least 2 labels describing it's contents
Qt Code:
  1. #ifndef collection_class
  2. #define collection_class
  3. #include <QWidget>
  4. #include <QLabel>
  5. #include <QVBoxLayout>
  6. #include <QGridLayout>
  7. class collection:public QWidget
  8. {
  9. private:
  10.  
  11.  
  12. static QVBoxLayout* mainLayout;
  13. QGridLayout innerLayout
  14. QLabel caption;
  15.  
  16. public:
  17. QSize sizeHint();
  18. collection(QWidget *parent,QString collectionName,QString collectionCaption);
  19. static QVBoxLayout* returnMainLayout();
  20. QLabel triClick;
  21.  
  22. };
  23. #endif
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "collection.h"
  2.  
  3. collection::collection(QWidget *parent, QString collectionName, QString collectionCaption)
  4. :QWidget(parent)
  5. {
  6.  
  7. innerLayout.setProperty("name",collectionName);
  8. triClick.setText(collectionName);
  9. caption.setText(collectionCaption);
  10. innerLayout.addWidget(&triClick,0,0);
  11. innerLayout.addWidget(&caption,0,1);
  12. mainLayout->addLayout(&innerLayout);
  13.  
  14. }
  15. static QVBoxLayout* collection::returnMainLayout()
  16. {
  17. return mainLayout;
  18. }
  19. QSize collection::sizeHint()
  20. {
  21. return QSize(100,200);
  22. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #ifndef scroll_class
  2. #define scroll_class
  3. #include "collection.h"
  4. #include <QScrollArea>
  5. class scroll:public QScrollArea
  6. {
  7. public:
  8. scroll(QWidget *parent=0);
  9. collection* addCollection(QString collectionName, QString collectionLabel);
  10. bool addWidget(QString collectionName, QWidget* object2Add,QString objectIdentifier);
  11. QSize sizeHint();
  12. };
  13. #endif
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "scroll.h"
  2. #include <QDebug>
  3. scroll::scroll(QWidget *parent)
  4. :QScrollArea(parent)
  5. {
  6.  
  7. setMaximumSize(200,80);
  8. // **** point of interest *****
  9. collection* collectionTmpPtr=new collection(this, "", "");
  10. collectionTmpPtr=new collection(this, "shoot", "wow");
  11. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  12. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  13. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  14. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  15. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  16. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  17. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  18. collectionTmpPtr=new collection(this, "shoot3S", "wow");
  19.  
  20. QWidget * widget=new QWidget(parent);
  21. VBoxLayout *mainLayout = collection::returnMainLayout() ;
  22. widget->setLayout(mainLayout);
  23. setWidget(widget);
  24.  
  25. }
  26. collection* scroll::addCollection(QString collectionName,QString collectionLabel)
  27. {
  28. collection* collectionTmpPtr=new collection(this, collectionName, collectionLabel);
  29. return collectionTmpPtr;
  30. }
  31. bool scroll::addWidget(QString collectionName, QWidget* object2Add, QString objectIdentifier)
  32. {
  33.  
  34. QVBoxLayout *mainLayout = collection::returnMainLayout();
  35.  
  36. for (int i = 0; i < mainLayout->count(); ++i)
  37. {
  38.  
  39. QLayout* item=mainLayout->itemAt(i)->layout();
  40. if (item !=0) //if item is a layout
  41. if (item->property("name")==collectionName) //if that's the collection user is looking for to add items to
  42. {
  43. object2Add->setProperty ("name",objectIdentifier);
  44. QGridLayout* newItem=static_cast<QGridLayout*>(item);
  45. newItem->addWidget(object2Add,newItem->count()-1,0);
  46. return true;
  47. }
  48.  
  49. }
  50. return false;
  51.  
  52. }
  53. QSize scroll::sizeHint()
  54. {
  55. return QSize(100,80);
  56. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include <QtGui>
  2. #include <QApplication>
  3. #include "scroll.h"
  4. QVBoxLayout* collection::mainLayout=new QVBoxLayout;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.  
  9. QApplication a(argc, argv);
  10. QWidget windows;
  11. scroll test(&windows);
  12. QVBoxLayout layout;
  13. test.addCollection("salam2","2");
  14. test.addCollection("salam3","2");
  15. test.addCollection("salam2","1");
  16. test.addCollection("salam4","3");
  17. test.addCollection("salam5","5");
  18. test.addCollection("salam2","2");
  19. test.addCollection("salam3","2");
  20. test.addCollection("salam2","1");
  21. test.addCollection("salam4","3");
  22. test.addCollection("salam5","5");
  23. test.addCollection("salam2","1");
  24. test.addCollection("salam4","3");
  25. test.addCollection("salam5","5");
  26.  
  27.  
  28. windows.setLayout(&layout);
  29. windows.show();
  30.  
  31. return a.exec();
  32. }
To copy to clipboard, switch view to plain text mode 
now the problem is that when i add collections in scroll constructor everything is fine like
following which i have used my custom scroll widget alone with 2 other widgets:

but when i add collections using add collection method which performs the same job,i have sizing issues like following:

the picture above shows my widget when some of the collections are added in scroll widget constructor and some of them are added in main.cpp using addCollection method,
if I add all collections in main then i would have NO collections being seen at all(i think they get zero size so they are not shown) i have played with sizepolicies and minimumSize methods but no luck,I'm Stuck,please help