Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot stop controls resizing
Qt 6.11 is out! See what's new in the release blog

Cannot stop controls resizing

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 759 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elpidiovaldez5
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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);
    }

    };
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved