# Example of usage SWidgetSwitcher ?

**URL:** <https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716>\
**Category:** UI\
**Tags:** unreal-engine, slate, CPP, question\
**Created:** [March 19, 2015, 3:36pm UTC](https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716 "2015-03-19T15:36:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syntopia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syntopia](https://forums.unrealengine.com/u/Syntopia)\
**Post date:** [March 19, 2015, 3:36pm UTC](https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716/1 "2015-03-19T15:36:51Z")

</div>

Please give an example of using slate SWidgetSwitcher. I can not understand…

---

<div class="post-metadata">

**Author:** ![Fiskislod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fiskislod](https://forums.unrealengine.com/u/Fiskislod)\
**Post date:** [March 20, 2015, 11:24am UTC](https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716/2 "2015-03-20T11:24:35Z")

</div>

Sure! The widget switcher has many children. But it only shows/presents one at a time. It’s as if the others did not exist. Here is some sample code:

```
// Caveat: I wrote this in a hurry and did not actually
// compile it. ;)

class SMyExample : public SCompoundWidget
{
    public:
    SLATE_BEGIN_ARGS(SMyExample)
    {}
    SLATE_END_ARGS()

    void Construct( const FArguments& InArgs )
    {
        TabIndex = 0;
        
        this->ChildSlot
        [
            SNew(SWidgetSwitcher)
            .WidgetIndex(this, &SMyExample::GetCurrentTabIndex)
            +SWidgetSwitcher::Slot()
            [
              SNew(STextBlock).Text(NSLOCTEXT("MyExample","Page1","Page One")
            ]
            +SWidgetSwitcher::Slot()
            [
              SNew(STextBlock).Text(NSLOCTEXT("MyExample","Page2","Page Two")
            ]
            +SWidgetSwitcher::Slot()
            [
              SNew(STextBlock).Text(NSLOCTEXT("MyExample","Page3","Page Three")
            ]
        ];
    }

private:
    int32 TabIndex;

    int32 GetCurrentTabIndex() const
    {
        return TabIndex;
    }

};

```

Now if you set `TabIndex`, you should be able to see _Page One_, _Page Two_, and _Page Three_ appear depending on whether you set the `TabIndex` to `0`, `1`, or `2`.

As a next step, you could use an `SVerticalBox` to add a row of buttons above the the switcher. If you set those buttons to change the `TabIndex`, you will have created a Tabs widgets. The upshot being that you have a lot of control over the appearance and behavior of these tabs as opposed to using a ready-made tabs widget. Indicentally, this is why we chose not to provide an out-of-the box Tab widget.

Let me know if this helps or if you have further questions. Also, if you do go on to make tabs out of this, could you post a simple code example? I think folks would appreciate seeing the code.

---

<div class="post-metadata">

**Author:** ![Syntopia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syntopia](https://forums.unrealengine.com/u/Syntopia)\
**Post date:** [March 20, 2015, 11:15pm UTC](https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716/3 "2015-03-20T23:15:04Z")

</div>

Thank you very much for your answer, now everything was clear. I think to create an article on the wiki, something like the “cookbook on slate”. A lot of good things scattered, I want to gather in one place. I will write about the tabs there, just to make an example of a little more interesting and post it for two three days.

---

<div class="post-metadata">

**Author:** ![Syntopia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syntopia](https://forums.unrealengine.com/u/Syntopia)\
**Post date:** [March 26, 2015, 11:01am UTC](https://forums.unrealengine.com/t/example-of-usage-swidgetswitcher/311716/4 "2015-03-26T11:01:43Z")

</div>

Post my buggy solution here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

 ![36010-minitabs.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/4/2949d3dafd4332e736ee8ae3cdabf6bf1de2d728.png)
