Guest User

Wt 3.2.2 GridLayout Problem

a guest
Aug 6th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include <Wt/WApplication>
  2. #include <Wt/WComboBox>
  3. #include <Wt/WContainerWidget>
  4. #include <Wt/WGridLayout>
  5. #include <Wt/WVBoxLayout>
  6. #include <Wt/WGroupBox>
  7. #include <Wt/WLabel>
  8. #include <Wt/WText>
  9. #include <Wt/WPushButton>
  10. #include <iostream>
  11.  
  12. class WtApp : public Wt::WApplication
  13. {
  14.    public:
  15.       WtApp( const Wt::WEnvironment& env);
  16.       ~WtApp() {}
  17.  
  18.    private:
  19.       Wt::WText *createText(const Wt::WString& text);
  20.       Wt::WWidget *createSelection();
  21.  
  22.    private:
  23.       Wt::WGridLayout* mLayout;
  24. };
  25.  
  26. WtApp::WtApp(const Wt::WEnvironment& env)
  27.    : Wt::WApplication(env)
  28.    , mLayout(new Wt::WGridLayout(root()))
  29. {
  30.    root()->setLayout(mLayout);
  31.  
  32.    // row 0
  33.    mLayout->addWidget(createText("Title"), 0, 0, 0, 3, Wt::AlignTop|Wt::AlignCenter);
  34.  
  35.  
  36.    // row 1
  37.    mLayout->addWidget(createText("SubTitle"), 1, 0, 1, 3, Wt::AlignMiddle|Wt::AlignCenter);
  38.  
  39.    // row 2
  40.    mLayout->addWidget(createSelection(), 2, 0, Wt::AlignLeft);
  41.    mLayout->addWidget(createText("Main Area"), 2, 1, Wt::AlignJustify);
  42.    mLayout->addWidget(createText("Details"), 2, 2, Wt::AlignJustify);
  43.  
  44.    // row 3
  45.    mLayout->addWidget(createText("More details"), 3, 0, 1, 3);
  46.  
  47.    /*
  48.     * Let row 2 and column 1 take the excess space.
  49.     */
  50.    mLayout->setRowStretch(2, 1);
  51.    mLayout->setRowStretch(3, 1);
  52.    mLayout->setColumnStretch(1, 1);
  53.    mLayout->setColumnStretch(2, 0);
  54.    mLayout->setColumnResizable(1);
  55.    mLayout->setRowResizable(2);
  56.    mLayout->setHorizontalSpacing(4);
  57.    mLayout->setVerticalSpacing(2);
  58.    mLayout->setContentsMargins(4, 4, 4, 4);
  59. }
  60.  
  61. Wt::WText *WtApp::createText(const Wt::WString& text)
  62. {
  63.    return new Wt::WText(text);
  64. }
  65.  
  66. Wt::WWidget *WtApp::createSelection()
  67. {
  68.    Wt::WContainerWidget *w = new Wt::WContainerWidget();
  69.    Wt::WGroupBox *gbox1 = new Wt::WGroupBox("Config");
  70.    gbox1->addWidget(createText("Config selection"));
  71.    Wt::WComboBox *cbox1  = new Wt::WComboBox();
  72.    cbox1->addItem("please select");
  73.    cbox1->addItem("System");
  74.    Wt::WGroupBox *gbox2 = new Wt::WGroupBox("Selection Box");
  75.    Wt::WComboBox *cbox2  = new Wt::WComboBox();
  76.    cbox2->addItem("please select");
  77.    cbox2->addItem("Entity 1");
  78.  
  79.    Wt::WVBoxLayout* gvbox2 = new Wt::WVBoxLayout();
  80.    gvbox2->addWidget(createText("Test 1"), 0, Wt::AlignTop);
  81.    gvbox2->addWidget(cbox2, 0, Wt::AlignTop);
  82.    gbox2->setLayout(gvbox2);
  83.  
  84.    Wt::WVBoxLayout* vbox = new Wt::WVBoxLayout();
  85.    vbox->setContentsMargins(4, 2, 4, 2);
  86.    vbox->addWidget(gbox1, 0, Wt::AlignTop);
  87.    vbox->addWidget(cbox1, 0, Wt::AlignTop);
  88.    vbox->addWidget(gbox2, 0, Wt::AlignTop);
  89.    vbox->addWidget(createText(""), 1);
  90.    w->setLayout(vbox);
  91.    return w;
  92. }
  93.  
  94. Wt::WApplication *createApplication(const Wt::WEnvironment& env)
  95. {
  96.    Wt::WApplication* myApplication = 0;
  97.    myApplication = new WtApp( env );
  98.    return myApplication;
  99. }
  100.  
  101. int main(int argc, char **argv)
  102. {
  103.    Wt::WRun(argc, argv, &createApplication);
  104.    return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment