#include <QtGui>
{
Q_OBJECT
public:
Window()
{
int spacing = 20;
spinbox->setStyleSheet("background: red");
spinbox->setValue(spacing);
label->setStyleSheet("background: blue");
label->setNum(spacing);
layout->addWidget(spinbox);
layout->addItem(spacer);
layout->addWidget(label);
connect(spinbox, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(setSpacing(int)));
}
private slots:
void setSpacing(int spacing)
{
spacer->changeSize(spacing, spacing);
layout()->invalidate();
}
private:
};
int main(int argc, char* argv[])
{
Window w;
w.show();
return a.exec();
}
#include "main.moc"
#include <QtGui>
class Window : public QWidget
{
Q_OBJECT
public:
Window()
{
int spacing = 20;
QSpinBox* spinbox = new QSpinBox(this);
spinbox->setStyleSheet("background: red");
spinbox->setValue(spacing);
QLabel* label = new QLabel(this);
label->setStyleSheet("background: blue");
label->setNum(spacing);
QVBoxLayout* layout = new QVBoxLayout(this);
spacer = new QSpacerItem(spacing, spacing);
layout->addWidget(spinbox);
layout->addItem(spacer);
layout->addWidget(label);
connect(spinbox, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(setSpacing(int)));
}
private slots:
void setSpacing(int spacing)
{
spacer->changeSize(spacing, spacing);
layout()->invalidate();
}
private:
QSpacerItem* spacer;
};
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
Window w;
w.show();
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
I suppose the spacing is not homogeneous over the layout? Otherwise you could simply use
Bookmarks