Set minimum size of widgets within a custom widget

6.4k Views Asked by At

I have a custumWidget which displays 3 QLineEdits. These customWidgets are stored inside a QListWidget like this:

QListWidgetItem* item = new QListWidgetItem();
ui->listWidget->insertItem(index, item);
ui->listWidget->setItemWidget(item, customWidget);

I set a minimum size within the customWidget:

ui->lineEndit->setMinimumSize(50, 200);

But when I resize the window, I can resize it even smaller than the stipulated minimumSize. Does my minimumSize get lost/ignored (for example, in my customWidget)?

I'm using Qt 5.1 and C++11.

1

There are 1 best solutions below

0
On

You should set the size policy for the line edit according to your needs. Take a look at enum QSizePolicy::Policy to find the right size policy.

ui->lineEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
ui->lineEdit->setMinimumSize(50,200);