Enable setting min and max list size

This commit is contained in:
WarmUpTill 2026-04-02 19:04:56 +02:00 committed by WarmUpTill
parent d15a324137
commit aadedbb610
2 changed files with 27 additions and 0 deletions

View File

@ -44,6 +44,16 @@ void ListEditor::SetPlaceholderText(const QString &text)
UpdatePlaceholder();
}
void ListEditor::SetMinListHeight(int value)
{
_minHeight = value;
}
void ListEditor::SetMaxListHeight(int value)
{
_maxHeight = value;
}
void ListEditor::UpdatePlaceholder()
{
bool visible = !_placeholder->text().isEmpty() && _list->count() == 0;
@ -104,11 +114,24 @@ int ListEditor::GetIndexOfSignal() const
void ListEditor::UpdateListSize()
{
SetHeightToContentHeight(_list);
if (_list->count() == 0 && !_placeholder->text().isEmpty()) {
auto height = _list->fontMetrics().height() * 3;
_list->setMinimumHeight(height);
_list->setMaximumHeight(height);
}
if (_minHeight >= 0 && _list->minimumHeight() != _minHeight) {
_list->setMinimumHeight(_minHeight);
}
if (_maxHeight >= 0 && _list->maximumHeight() != _maxHeight) {
if (_list->minimumHeight() > _maxHeight) {
_list->setMinimumHeight(_maxHeight);
}
_list->setMaximumHeight(_maxHeight);
}
adjustSize();
updateGeometry();
}

View File

@ -15,6 +15,8 @@ public:
ListEditor(QWidget *parent = nullptr, bool reorder = true);
int count() const { return _list->count(); };
void SetPlaceholderText(const QString &text);
void SetMinListHeight(int);
void SetMaxListHeight(int);
protected:
void showEvent(QShowEvent *);
@ -38,6 +40,8 @@ protected:
private:
QLabel *_placeholder;
int _minHeight = -1;
int _maxHeight = -1;
};
} // namespace advss