Add a MiniQtHelper to set spacing/margins on layouts

This commit is contained in:
baldurk
2026-09-11 21:17:19 +01:00
parent 3579ecc065
commit 48b968e9a7
4 changed files with 51 additions and 0 deletions
+17
View File
@@ -676,6 +676,23 @@ added anywhere.
)");
virtual void InsertWidget(QWidget *parent, int32_t index, QWidget *child) = 0;
DOCUMENT(R"(Set the internal spacing in pixels between items. If the widget is not a layout
(either grid or horizontal/vertical) this call will have no effect.
:param QWidget layout: The layout widget.
:param int spacing: The spacing in pixels to use between items
)");
virtual void SetLayoutSpacing(QWidget *layout, int spacing) = 0;
DOCUMENT(R"(Set the external margins on the outside of all of the items in the layout. If
the widget is not a layout (either grid or horizontal/vertical) this call will have no effect.
:param QWidget layout: The layout widget.
:param int horizontal: The horizontal margins on the left and right.
:param int vertical: The vertical margins on the top and bottom.
)");
virtual void SetLayoutMargins(QWidget *layout, int horizontal, int vertical) = 0;
// widget manipulation
DOCUMENT(R"(Set the 'text' of a widget. How this manifests depends on the type of the widget, for
+24
View File
@@ -307,6 +307,30 @@ void MiniQtHelper::InsertWidget(QWidget *parent, int32_t index, QWidget *child)
box->insertWidget(qMin(qMax(0, index), box->count()), child);
}
void MiniQtHelper::SetLayoutSpacing(QWidget *layout, int spacing)
{
if(!layout)
return;
QLayout *l = layout->layout();
if(!l)
return;
l->setSpacing(spacing);
}
void MiniQtHelper::SetLayoutMargins(QWidget *layout, int horizontal, int vertical)
{
if(!layout)
return;
QLayout *l = layout->layout();
if(!l)
return;
l->setContentsMargins(horizontal, vertical, horizontal, vertical);
}
void MiniQtHelper::SetWidgetText(QWidget *widget, const rdcstr &text)
{
if(!widget)
+2
View File
@@ -68,6 +68,8 @@ public:
int32_t columnSpan) override;
void AddWidget(QWidget *parent, QWidget *child) override;
void InsertWidget(QWidget *parent, int32_t index, QWidget *child) override;
void SetLayoutSpacing(QWidget *layout, int spacing) override;
void SetLayoutMargins(QWidget *layout, int horizontal, int vertical) override;
// widget manipulation
@@ -170,6 +170,14 @@ struct MiniQtInvoker : UIThreadInvoker<IMiniQtHelper>
{
InvokeVoidFunction(&IMiniQtHelper::InsertWidget, parent, index, child);
}
void SetLayoutSpacing(QWidget *layout, int spacing)
{
InvokeVoidFunction(&IMiniQtHelper::SetLayoutSpacing, layout, spacing);
}
void SetLayoutMargins(QWidget *layout, int horizontal, int vertical)
{
InvokeVoidFunction(&IMiniQtHelper::SetLayoutMargins, layout, horizontal, vertical);
}
// widget manipulation