Slate Window sizing

Here is how I’m creating the SWindow

RowWindow = SNew(SWindow)
	.AutoCenter(EAutoCenter::None)
	.Title(FText::FromString(TEXT("Add New Lines")))
	.IsInitiallyMaximized(false)
	.ScreenPosition(FVector2D(100, 100))
	.CreateTitleBar(true)		
	.SizingRule(ESizingRule::Autosized)
	.SupportsMaximize(false)
	.SupportsMinimize(true)
	.HasCloseButton(true)
	.Style(&WindowStyle)
	[
		BuildEditableBox()			
	];

Then, called in BuildEditableBox(), I’m building the rows that populate the SWindow:

I am using “ManualWidth” to try and have the columns be wide enough for the content inside the rows. They seem to autosize based on the column name, not the content in rows below..

SAssignNew(LamsAddedRowsWidget, SListView<TSharedPtr<FLAMSWidgetRowData>>)
	.ItemHeight(20)
	.ScrollBarStyle(&ScrollStyle)
	.ListViewStyle(&TableViewStyle)
	.ListItemsSource(&DisplayArray)
	.SelectionMode(ESelectionMode::Multi)
	.OnGenerateRow_Raw(this, &SLAMSDataEntryWidget::MakeRowDataListViewWidget)
	.OnSelectionChanged_Raw(this, &SLAMSDataEntryWidget::EntrySelectionChanged)
	.OnKeyDownHandler_Raw(this, &SLAMSDataEntryWidget::OnKeyDown)
	.HeaderRow(
		SNew(SHeaderRow)
		.Style(&HeaderStyle)
		+ SHeaderRow::Column("Select").DefaultLabel(NSLOCTEXT("LAMSData", "SelectColumn", "Select"))						.ManualWidth(AdjustedSize.X * 0.03)
		+ SHeaderRow::Column("Section").DefaultLabel(NSLOCTEXT("LAMSData", "SectionColumn", "Section"))						.ManualWidth(AdjustedSize.X * 0.1)
		+ SHeaderRow::Column("SubSection").DefaultLabel(NSLOCTEXT("LAMSData", "SubSectionColumn", "SubSection"))			        .ManualWidth(AdjustedSize.X * 0.12)
    		+ SHeaderRow::Column("SubSectionType").DefaultLabel(NSLOCTEXT("LAMSData", "SubSectionTypeColumn", "SubSectionType"))                    .ManualWidth(AdjustedSize.X * 0.05)
    		+ SHeaderRow::Column("PrecedingLine").DefaultLabel(NSLOCTEXT("LAMSData", "PrecedingLineColumn", "Preceding Line"))	                .ManualWidth(AdjustedSize.X * 0.15)
    		+ SHeaderRow::Column("Character").DefaultLabel(NSLOCTEXT("LAMSData", "CharacterColumn", "Character"))				        .ManualWidth(AdjustedSize.X * 0.08)
    		+ SHeaderRow::Column("LineType").DefaultLabel(NSLOCTEXT("LAMSData", "LineTypeColumn", "Line Type"))					.ManualWidth(AdjustedSize.X * 0.05)
		+ SHeaderRow::Column("UniqueName").DefaultLabel(NSLOCTEXT("LAMSData", "UniqueNameColumn", "Unique Name"))			        .ManualWidth(AdjustedSize.X * 0.20)
		+ SHeaderRow::Column("Direction").DefaultLabel(NSLOCTEXT("LAMSData", "DirectionColumn", "Direction"))				        .ManualWidth(AdjustedSize.X * 0.08)
		+ SHeaderRow::Column("Location").DefaultLabel(NSLOCTEXT("LAMSData", "LocationColumn", "Location"))					.ManualWidth(AdjustedSize.X * 0.08)
		+ SHeaderRow::Column("Text").DefaultLabel(NSLOCTEXT("LAMSData", "TextColumn", "Text"))							.ManualWidth(AdjustedSize.X * 0.25)
		+ SHeaderRow::Column("Remove").DefaultLabel(NSLOCTEXT("LAMSData", "RemoveColumn", "Remove"))						.ManualWidth(AdjustedSize.X * 0.035))

Here is how I am calculating the “AdjustedSize” member:

float DPI_Scale = -1;
	FVector2D viewportSize(0, 0);
	if (GEditor && MainPluginTab)
	{
		FIntPoint SizeXY;
 
		FViewport* Viewport = GEditor->GetActiveViewport();
		SizeXY = Viewport ? Viewport->GetSizeXY() : FIntPoint(2000,1000);
		viewportSize = FVector2D(SizeXY.X, SizeXY.Y);
		int32 X = FGenericPlatformMath::FloorToInt((float)SizeXY.X);
		int32 Y = FGenericPlatformMath::FloorToInt((float)SizeXY.Y);
		DPI_Scale = GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(X, Y));
	}
 
	AdjustedSize = DPI_Scale == -1 ? FVector2D(2000, 1000) : (1 / DPI_Scale) * viewportSize;

Steps to Reproduce

I’m having a lot of trouble reliably creating an SWindow with a width that does not overflow past the edge of my screen.

It’s worth noting that this was all working fine in UE5.4 - something in UE5.5 seemed to have broken it. I’ve tried a variety of workarounds to no success.

There are many different users that are accessing this widget from different monitors. I’d like to auto size the window so the columns are sized appropriately, while constraining the total window width.

I’ve include the code for my widget setup. Please let me know

Thank you!

Hi Steven,

Sorry about the delay. I’m looking into this now and should get back to you soon.

Best regards,

Vitor

Hi [mention removed]​ - I 've figured this out! We can close out this ticket. Thank you.

That’s great to hear! Would you mind sharing what you needed to do to achieve the desired result?

Hi [mention removed]​ - I needed to set the SHeaderRow::Column to use Fill Width.

Then, I also needed to force the outer “SBox” to set the width to AdjustedSize.X.

float ActualWidth = AdjustedSize.X;
SNew(SBox)
.WidthOverride(ActualWidth)
[
	SNew(SBorder)
		.Padding(10)
		.Content()
		[
			SNew(SVerticalBox)
				+ SVerticalBox::Slot()
				.VAlign(VAlign_Top)
				.AutoHeight()
				[
					SAssignNew(AddedRowsWidget, SListView<TSharedPtr<FWidgetRowData>>)
						.ItemHeight(20)
						.ScrollBarStyle(&ScrollStyle)
						.ListViewStyle(&TableViewStyle)
						.ListItemsSource(&DisplayArray)
						.SelectionMode(ESelectionMode::Multi)
						.OnGenerateRow_Raw(this, &SLAMSDataEntryWidget::MakeRowDataListViewWidget)
						.OnSelectionChanged_Raw(this, &SLAMSDataEntryWidget::EntrySelectionChanged)
						.OnKeyDownHandler_Raw(this, &SLAMSDataEntryWidget::OnKeyDown)
						.HeaderRow(
							SNew(SHeaderRow)
							.Style(&HeaderStyle)
							+ SHeaderRow::Column("Select").DefaultLabel(NSLOCTEXT("Data", "SelectColumn", "Select"))								.FillWidth((ActualWidth / 24.f)/ActualWidth)
							+ SHeaderRow::Column("Section").DefaultLabel(NSLOCTEXT("Data", "SectionColumn", "Section"))								.FillWidth((ActualWidth / 10.f)/ActualWidth)
							+ SHeaderRow::Column("SubSection").DefaultLabel(NSLOCTEXT("Data", "SubSectionColumn", "SubSection"))					.FillWidth((ActualWidth / 8.f )/ActualWidth)
							+ SHeaderRow::Column("SubSectionType").DefaultLabel(NSLOCTEXT("Data", "SubSectionTypeColumn", "SubSectionType"))		.FillWidth((ActualWidth / 18.f)/ActualWidth)
							+ SHeaderRow::Column("PrecedingLine").DefaultLabel(NSLOCTEXT("Data", "PrecedingLineColumn", "Preceding Line"))			.FillWidth((ActualWidth / 8.f )/ActualWidth)
							+ SHeaderRow::Column("Character").DefaultLabel(NSLOCTEXT("Data", "CharacterColumn", "Character"))						.FillWidth((ActualWidth / 12.f)/ActualWidth)
							+ SHeaderRow::Column("LineType").DefaultLabel(NSLOCTEXT("Data", "LineTypeColumn", "Line Type"))							.FillWidth((ActualWidth / 20.f)/ActualWidth)
							+ SHeaderRow::Column("UniqueName").DefaultLabel(NSLOCTEXT("Data", "UniqueNameColumn", "Unique Name"))					.FillWidth((ActualWidth / 8.f )/ActualWidth)
							+ SHeaderRow::Column("Direction").DefaultLabel(NSLOCTEXT("Data", "DirectionColumn", "Direction"))						.FillWidth((ActualWidth / 12.f)/ActualWidth)
							+ SHeaderRow::Column("Location").DefaultLabel(NSLOCTEXT("Data", "LocationColumn", "Location"))							.FillWidth((ActualWidth / 12.f)/ActualWidth)
							+ SHeaderRow::Column("Text").DefaultLabel(NSLOCTEXT("Data", "TextColumn", "Text"))										.FillWidth((ActualWidth / 8.f )/ActualWidth)
							+ SHeaderRow::Column("Remove").DefaultLabel(NSLOCTEXT("Data", "RemoveColumn", "Remove"))								.FillWidth((ActualWidth / 24.f)/ActualWidth))
				]
		]
];

I’m having other issues with calling SWindow::Resize() on the window that contains this SListView, but I’ll have to save that for another question.