Qt: Various layout fixes

This commit is contained in:
spycrab
2018-03-18 00:06:44 +01:00
parent 7465906a0f
commit 1b06e66f1d
5 changed files with 21 additions and 17 deletions

View File

@ -10,7 +10,8 @@
#include <QVBoxLayout>
#include <QWidget>
QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize, int margin)
QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize, int margin_width,
int margin_height)
{
auto* scroll = new QScrollArea;
scroll->setWidget(wrapped_widget);
@ -20,8 +21,9 @@ QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize, int margi
if (to_resize != nullptr)
{
// For some reason width() is bigger than it needs to be.
int recommended_width = wrapped_widget->width() * 0.9;
int recommended_height = wrapped_widget->height() + margin;
auto min_size = wrapped_widget->minimumSizeHint();
int recommended_width = min_size.width() + margin_width;
int recommended_height = min_size.height() + margin_height;
to_resize->resize(std::max(recommended_width, to_resize->width()),
std::max(recommended_height, to_resize->height()));

View File

@ -7,7 +7,8 @@
class QLayout;
class QWidget;
QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize = nullptr, int margin = 50);
QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize = nullptr,
int margin_width = 50, int margin_height = 50);
// Wrap wrapped_layout in a QScrollArea and fill the parent widget with it
void WrapInScrollArea(QWidget* parent, QLayout* wrapped_layout, QWidget* to_resize = nullptr);