Menu

Dynamically create tabs in WDTabWidget

Acacia
2015-06-04
2015-06-05
  • Acacia

    Acacia - 2015-06-04

    Hello, I tried to create a tree structure using multiple file dwo. In the main file there are three containers: top container that contains menu, bottom container containing status bar and finally middle container (wdtabwidget) in which I have to dynamically create tabs. The only way to show the content of the new tab is:

    Newtab *NewmyTab = new Newtab();
    main_one->MiddleContainer->addTab(Newmytab->top,"Description",false);
    main_one->MiddleContainer->setCurrentWidget(Newmytab->top);

    but the sizes of the new generated tab are not congruent with the sizes of the container.
    I tried to create a new WDSContainerWidgets and then create the new Tab setting the parent to it and then adding this container as tab of the MiddleContainer, but the new tab does not contain anything.
    If I try to add not Newmytab->top but directly the Newmytab as new tab, the Newmytab overwrites the wdtabwidget.

    Have you any suggestion?
    thanks

     

    Last edit: Acacia 2015-06-04
    • Nigel Lea

      Nigel Lea - 2015-06-04

      Hello Acacia

      Your problem has revealed a deficiency in WDTabWidget, it is not easy to attach a design to a newly created tab. We hope to correct this in the next release of DesignerWt.

      As it is easy to attach a design to an existing (container) tab (one created in DesignerWt), then you could consider creating several container tabs in MiddleContainer and using the setTabHidden method of WDTabWidget to hide the tabs not in use.

      Otherwise you could use the code given below. This dynamically adds to the layout structure of the main_one design to create a new container tab. The second design is then attached to this tab.

            //create the main design
            main_one = new design1(root());
      
            //create a new container tab within MiddleContainer
            DSNode *newtab_dsnode = new 
                   DSNode(main_one->AllNodes->MiddleContainer_pNode,
                          "newtab0","WDContainerWidget",true);
            newtab_dsnode->attribs.set("pinleft","$p:0");
            newtab_dsnode->attribs.set("pinright","$p:0");
            newtab_dsnode->attribs.set("pintop","$p:0");
            newtab_dsnode->attribs.set("pinbottom","$p:0");
            newtab_dsnode->attribs.set("tabtitle","New Tab 0");
            newtab_dsnode->createLevel(main_one);
      
            //Attach the second design to the new tab
            Newmytab = new Newtab((WDContainerWidget *)newtab_dsnode->pWidget);
      
            //Note: to remove the tab do the following, in the given order
            //delete Newmytab;
            //delete newtab_dsnode;
      

      I hope that one of these approaches will prove to be an acceptable workaround until the next release of DesignerWt.

      Regards

      Nigel

       
      • Acacia

        Acacia - 2015-06-05

        Thank you. I've tried both the solutions. But only the first one is working. The second one opens a new tab but it is empty. However I've another question about the popup menu related to their colours and formatting. It always appear a small circle on the left of all items with different background colour and without the arrow on the right side for the submenus. This behaviour does not appear whenever I do the preview by the designer.
        Thank you.

        Lorenzo

         
        • Nigel Lea

          Nigel Lea - 2015-06-05

          Lorenzo

          I'm suprised that the second solution didn't work. Possibly you are not adding the tab in the session constructor, in which case you will need to do

              newtab1_dsnode->recalcNode();
          

          after attaching the second design.

          If you still have a problem then perhaps you could attach designs (.dwo's) and source code to a post so that I can diagnose the problem.

          I haven't seen the problem with popup menus that you describe. Does this behaviour happen with the popup menu in Example1? Again I am happy to investigate further if you supply a design file.

          Regards

          Nigel

           

Log in to post a comment.

MongoDB Logo MongoDB