ue4单选框设置

    技术2024-06-09  80

    奇怪的是,ue4只有多选框,原来合并了。

    .Style(FCoreStyle::Get(), "RadioButton")

     

    不多说了,放代码

    先枚举几个     enum ERadioChoice     {         Radio0,         Radio1,         Radio2,     };

     

                       + SHorizontalBox::Slot()                     .AutoWidth()                     [                         CreateRadioButton(LOCTEXT("SRadioButtonItemLabel01", "左"), Radio0)                     ]

                    + SHorizontalBox::Slot()                     .AutoWidth()                     [                         CreateRadioButton(LOCTEXT("SRadioButtonItemLabel02", "中"), Radio1)                     ]

                    + SHorizontalBox::Slot()                     .AutoWidth()                     [                         CreateRadioButton(LOCTEXT("SRadioButtonItemLabel03", "右"), Radio2)                     ]

       TSharedRef<SWidget> CreateRadioButton(const FText& RadioText, ERadioChoice RadioButtonChoice)     {         return SNew(SCheckBox)             .Style(FCoreStyle::Get(), "RadioButton")             .IsChecked(this, &SProjectInfo_cabinetUnion::HandleRadioButtonIsChecked, RadioButtonChoice)             .OnCheckStateChanged(this, &SProjectInfo_cabinetUnion::HandleRadioButtonCheckStateChanged, RadioButtonChoice)             [                 SNew(STextBlock)                 .Text(RadioText)             ];     }     // Callback for determining whether a radio button is checked.     ECheckBoxState HandleRadioButtonIsChecked(ERadioChoice ButtonId) const     {         return (_radioChoice == ButtonId)             ? ECheckBoxState::Checked             : ECheckBoxState::Unchecked;     }     // Callback for checking a radio button.     void HandleRadioButtonCheckStateChanged(ECheckBoxState NewRadioState, ERadioChoice RadioThatChanged)     {         if (NewRadioState == ECheckBoxState::Checked)         {             _radioChoice = RadioThatChanged;         }     }

        // 单选选项     ERadioChoice _radioChoice;

    Processed: 0.012, SQL: 9