How to convert the following blueprint to c++

Hi friends… I am new to blueprint. I was wondering if someone can guide me on how to convert the following blue print to c++.

Background on what im working on. I created a widget that that has a check box & text so I can bind it from another widget to display list of items as check box option in my combobox.

So to recap quickly.

  1. How to convert the blueprint in attached screen to c++?

Thanks in advance for taking the time for helping me.

Hey @TrackLight. Here I leave you an example of a widget implemented in c++. For this to work you need to add the “UMG” module in your project’s Build.cs file. Just add the string “UMG” in the list of public module dependencies and you should be good to go.

A VERY important property specifier to use when programming widgets in c++ is the
UPROPERTY(meta = (BindWidget)). This allows you to reference widgets and other similar component from your designer view in blueprints, just like the TextBlock in this case. It could also be used to reference other classes used in this way, even other UUserWidgets that you may use inside this one.

One thing that I’m not sure how to replicate, is this EventConstruct that you are showing here, I’m not sure what it is or where exactly to replicate its behavior in c++. But it looks like you can get away with calling a custom “Construct” or “Initialize” method implemented in c++ and calling it here in blueprint (just a suggestion though).

Anyway, here is the code example:

.h file

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "TestWidget.generated.h"

class UTextBlock;

/**
 * 
 */
UCLASS()
class TESTPROJECT_API UTestWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
	UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
	UTextBlock* TestTextBlock;

	UFUNCTION(BlueprintCallable)
	virtual void SetText(FText InText);
};

.cpp file

#include "TestWidget.h"
#include "Components/TextBlock.h"

void UTestWidget::SetText(FText InText)
{
	TestTextBlock->SetText(InText);
}

Hope this helps.

Edit: Oh, and you need to implement a blueprint that inherits from this c++ class, so that you can work with UMG Designer features to design your widget

1 Like

Thank you kribbeck. I will look into the above example.