[UE4][UMG]How to drag item to ScrollBox using C++
override NativeOnDragDetected() in the class which is draping from.
example source:
void UItemSlotWidget::NativeOnDragDetected(const FGeometry& InGeometry,
const FPointerEvent& InMouseEvent,
UDragDropOperation*& OutOperation)
{
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);
RTS_PlayerController->SetInputMode_UI_Only();
OutOperation = CreateItemDrag();
}
FReply UItemSlotWidget::NativeOnMouseButtonDown(const FGeometry & InGeometry, const FPointerEvent & InMouseEvent)
{
FReply reply = Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
SetTextToInformationBar();
if (InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton) {
reply.DetectDrag(TakeWidget(), EKeys::LeftMouseButton);
}
return reply;
}
UDragDropOperation* UItemSlotWidget::CreateItemDrag() const {
auto drag_drop_operation = NewObject<UItemDrag>();
if (RTS_PlayerController && !IsEmpty()) {
RTS_PlayerController->DragDropOp_property = drag_drop_operation; // for garbage collector
drag_drop_operation->DraggedItem = const_cast<UItemSlotWidget*>(this);
drag_drop_operation->ItemImage = currentImage_Texture2D;
auto DragVisual = CreateWidget<UDraggedItem>(RTS_PlayerController, URTS_FunctionLibrary::GetClassPtrOf_DraggedItem_BP());
DragVisual->ImageOfDraggedItem = NewObject<UImage>();
DragVisual->ImageOfDraggedItem->SetBrushFromTexture(currentImage_Texture2D);
drag_drop_operation->DefaultDragVisual = DragVisual;
drag_drop_operation->Pivot = EDragPivot::MouseDown;
}
return drag_drop_operation;
}
一段路,走了很久依然看不到希望,那就改变方向。生活个性说说大全。