mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[QtUtils] Add layout creation and relayout helpers (#7619)
* [QtUtils] Add layout creation and relayout helpers * Swap parameter order (spacing before margin) and remove static from relayout() --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
67a212d677
commit
06b9ca368f
1 changed files with 34 additions and 0 deletions
|
|
@ -73,6 +73,40 @@ static inline void clearLayoutRec(QLayout *l, DeletePolicy policy = DeletePolicy
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a layout of type @c LayoutT with zero margins.
|
||||
*
|
||||
* @param parent Parent widget, or nullptr when the layout is added later.
|
||||
* @param spacing Optional spacing. Values below zero leave the style's default spacing
|
||||
* untouched; pass a non-negative value to call setSpacing().
|
||||
* @param margin Uniform margin. Defaults to zero.
|
||||
*/
|
||||
template <typename LayoutT> LayoutT *makeLayout(QWidget *parent = nullptr, int spacing = -1, int margin = 0)
|
||||
{
|
||||
auto *layout = new LayoutT(parent);
|
||||
layout->setContentsMargins(margin, margin, margin, margin);
|
||||
if (spacing >= 0) {
|
||||
layout->setSpacing(spacing);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Forces @p layout to recompute and repaint immediately.
|
||||
*
|
||||
* Convenience for the invalidate/activate/update sequence used after changing a layout's
|
||||
* contents outside of a resize event.
|
||||
*/
|
||||
inline void relayout(QLayout *layout)
|
||||
{
|
||||
if (!layout) {
|
||||
return;
|
||||
}
|
||||
layout->invalidate();
|
||||
layout->activate();
|
||||
layout->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a QScrollArea using the conventions the client applies nearly everywhere:
|
||||
* the inner widget resizes with the viewport and the horizontal bar is disabled.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue