I'm a total newbie, so don't be mean if this is total bogus. I want to write a pretty complex GUI, but I really don't want to write all my code into one single class. Does everything that's going to be in one window has to be in one class ? From what I already read I can create custom Widgets and add them into my code. But when I try, it doesn't work: The custom widget is always a seperate window. So I hope anybody can help me. I'm assuming I'm making a trivial mistake. I just can't find a tutorial for this since everybody just creates one custom widget and opens it from main as a new window. But I want to include my custom widget *into* the window.
I made a real simple version of my problem. Just two groupBoxes each having a button which are supposed to be on top of each other within ONE window. The top button represents everything I want to add from myWidget, the bottom one stands for all the other stuff (propably other custom widgets). The problem is they are always in different windows. How can I get them into one? Please tell me why my thinking is wrong!
So here goes nothing:

#myWidget.cpp
Qt Code:
  1. #include "mywidget.h"
  2.  
  3. #include <QGroupBox>
  4. #include <QHBoxLayout>
  5. #include <QPushButton>
  6.  
  7. myWidget::myWidget(QWidget *parent) : QWidget(parent)
  8. {
  9. QGroupBox *grInMyW = new QGroupBox("Group In myWidget");
  10. QHBoxLayout *layInMyW = new QHBoxLayout();
  11. QPushButton *butInMyW = new QPushButton("Button in myWidget");
  12.  
  13. layInMyW->addWidget(butInMyW);
  14. grInMyW->setLayout(layInMyW);
  15. grInMyW->setVisible(true);
  16. }
To copy to clipboard, switch view to plain text mode 

#main.cpp
Qt Code:
  1. #include "mywidget.h"
  2.  
  3. #include <QApplication>
  4. #include <QGroupBox>
  5. #include <QVBoxLayout>
  6. #include <QPushButton>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication a(argc, argv);
  11. QGroupBox *gr = new QGroupBox();
  12. QVBoxLayout *layout = new QVBoxLayout();
  13.  
  14. myWidget *myW = new myWidget;
  15. QPushButton* butInMain = new QPushButton("Button in Main");
  16.  
  17. layout->addWidget(myW);
  18. layout->addWidget(butInMain);
  19. gr->setLayout(layout);
  20. gr->show();
  21. return a.exec();
  22. }
To copy to clipboard, switch view to plain text mode 

I don't know if I even need the GroupBoxes, but I read that for a custom widget i have to include some Layout, for its size to be clear. If there is an easier way, I'd really appreciate you telling me !
But I'd be thankful for any answer I can get !!