Skip to content

Commit

Permalink
try a grid layout
Browse files Browse the repository at this point in the history
  • Loading branch information
toloudis committed Feb 13, 2024
1 parent d31fc29 commit 5d337a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
33 changes: 33 additions & 0 deletions agave_app/Controls.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Controls.h"

#include <QColorDialog>
#include <QLabel>
#include <QPaintEvent>
#include <QPainter>
#include <QPainterPath>
Expand Down Expand Up @@ -510,3 +511,35 @@ QIntSlider::setTracking(bool enabled)
{
m_slider.setTracking(enabled);
}

void
MyFormLayout::addRow(const QString& label, QWidget* widget)
{
int row = rowCount();
addWidget(new QLabel(label), row, 0);
addWidget(widget, row, 1);
}

QFormLayout*
Controls::createFormLayout(QWidget* parent)
{
QFormLayout* layout = new QFormLayout(parent);
initFormLayout(*layout);
return layout;
}
void
Controls::initFormLayout(QFormLayout& layout)
{
layout.setRowWrapPolicy(QFormLayout::DontWrapRows);
layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
layout.setFormAlignment(Qt::AlignHCenter | Qt::AlignTop);
layout.setLabelAlignment(Qt::AlignRight);
}

MyFormLayout*
Controls::createMyFormLayout(QWidget* parent)
{
MyFormLayout* layout = new MyFormLayout(parent);
// initFormLayout(*layout);
return layout;
}
26 changes: 14 additions & 12 deletions agave_app/Controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,24 @@ private slots:
QSlider m_slider;
};

class Controls
class MyFormLayout : public QGridLayout
{
Q_OBJECT
public:
static QFormLayout* createFormLayout(QWidget* parent = nullptr)
MyFormLayout(QWidget* parent = nullptr)
: QGridLayout(parent)
{
QFormLayout* layout = new QFormLayout(parent);
initFormLayout(*layout);
return layout;
}
static void initFormLayout(QFormLayout& layout)
{
layout.setRowWrapPolicy(QFormLayout::DontWrapRows);
layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
layout.setFormAlignment(Qt::AlignHCenter | Qt::AlignTop);
layout.setLabelAlignment(Qt::AlignRight);
}
void addRow(const QString& label, QWidget* widget);
};

class Controls
{
public:
static QFormLayout* createFormLayout(QWidget* parent = nullptr);
static void initFormLayout(QFormLayout& layout);

static MyFormLayout* createMyFormLayout(QWidget* parent = nullptr);
};

/**
Expand Down

0 comments on commit 5d337a5

Please sign in to comment.