Project

General

Profile

Moving Tabs between WTabWidgets

Added by Dennis Schenzow almost 7 years ago

Hello,

I'm trying to move tabs between 2 different WTabWidgets and need a help at cleanly removing/adding tabs to the tabWidgets.

I fill the tabWidget1 with items and add it (and the empty tabWidget2) to a WGridLayout.

    auto tabWidget1 = std::make_unique<WTabWidget>();
    WMenuItem* tab1 = tabWidget1->addTab(
                std::make_unique<WTextArea>("tab 1 contant"),
                "tab1",
                ContentLoading::NextLevel);
    WMenuItem* tab2 = tabWidget1->addTab(
                std::make_unique<WTextArea>("tab 2 contant"),
                "tab2",
                ContentLoading::NextLevel);
    auto tabWidget1Raf = gridLayout->addWidget(std::move(tabWidget1), 1, 1);
    // create emty second tabWidget
    auto tabWidget2Raf = gridLayout->addWidget(std::make_unique<WTabWidget>(), 2, 1);

currently i use this code to delete a tab from his parent and add it to the second tabWidget:

    Wt::WWidget* itemContent = tab1->contents();

    if(-1 == tabWidget2Raf->indexOf(itemContent)){// tab1 is not in tabWidget2 (yet!)
        // remove first the itemContant and than the item from privious tabWidget
        std::unique_ptr<WWidget> itemContantUnique = itemContent->removeFromParent();
        std::unique_ptr<WWidget> itemUnique = tab1->removeFromParent();
        // add the tab1 to tabWidget2 and get the new pointer to tab1
        tab1 = tabWidget2->addTab(std::move(itemContantUnique),
                                  tab1->text(),
                                  Wt::ContentLoading::NextLevel);

The problem is, that the tab1 is not completely deleted from the tabWidget1, so when moving the tab1 back the check @ if(1 == tabWidget1Raf>indexOf(itemContent)) @ doesn't trigger.

I tried to delete the tab1 with WTabWidget functions, like std::unique_ptr<WWidget> tab1Unique = tabWidgetPrime->removeTab(tab1);, but either i couldn't manage to add the returned value to tabWidget2 or the app crashed.

regards,

dennis