Cannot stop controls resizing
-
I am trying to fix the size of some controls in a widget. Unfortunately nothing I do stops them from re-sizing.
The code is for a widget that contains a linked text box and slider for inputting a numeric value. I set the size policy to fixed on everything I can think of. What is the problem ?The widget is embedded in a widget with a QFormLayout, and this is inside a QScrollArea. I notice that the scrollbars never appear. Instead the contents of the form shrink.
@
class DynamicDataSlider : public QWidget {
Q_OBJECTpublic:
IntRange *param;
QSlider *slider;
QLineEdit *text;DynamicDataSlider(IntRange *p) {
param = p;text = new QLineEdit(); text->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QObject::connect(text, SIGNAL(editingFinished()), this, SLOT(setSliderValue())); slider = new QSlider(Qt::Horizontal); slider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); slider->setRange(param->min, param->max); slider->setValue(param->defaultValue); slider->setTracking(true); QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setTextBoxValue(int))); QHBoxLayout *layout = new QHBoxLayout(); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); layout->addWidget(text); layout->addWidget(slider); setLayout(layout); emit setTextBoxValue(param->defaultValue);
}
public slots:
void setTextBoxValue(int val) {
param->setValue(val);
QString str;
str.setNum(val);
text->setText(str);
}void setSliderValue() {
int newVal = text->displayText().toInt();
slider->setSliderPosition(newVal);
}};
@