mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make the combo box drop down menus fit the text content even if the widget itself doesn't.
This commit is contained in:
parent
bf8ed71641
commit
a7aef3f4e7
@ -230,6 +230,25 @@ void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
{
|
{
|
||||||
m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
||||||
m_comboBox->setMinimumContentsLength(m_attributes.minimumContentsLength);
|
m_comboBox->setMinimumContentsLength(m_attributes.minimumContentsLength);
|
||||||
|
// Make sure the popup adjusts to the content even if the widget itself doesn't
|
||||||
|
QFont font = m_comboBox->view()->font();
|
||||||
|
|
||||||
|
int maxTextWidth = 0;
|
||||||
|
bool labelsElided = false;
|
||||||
|
for (const PdmOptionItemInfo& option : options)
|
||||||
|
{
|
||||||
|
QString label = option.optionUiText();
|
||||||
|
if (label.size() > m_attributes.maximumMenuContentsLength)
|
||||||
|
{
|
||||||
|
label.resize(m_attributes.maximumMenuContentsLength);
|
||||||
|
labelsElided = true;
|
||||||
|
}
|
||||||
|
maxTextWidth = std::max(maxTextWidth, QFontMetrics(font).boundingRect(label).width());
|
||||||
|
}
|
||||||
|
|
||||||
|
int marginWidth = m_comboBox->view()->contentsMargins().left() + m_comboBox->view()->contentsMargins().right();
|
||||||
|
m_comboBox->view()->setMinimumWidth(maxTextWidth + marginWidth);
|
||||||
|
m_comboBox->view()->setTextElideMode(labelsElided ? Qt::ElideMiddle : Qt::ElideNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_attributes.enableEditableContent)
|
if (m_attributes.enableEditableContent)
|
||||||
|
@ -61,17 +61,18 @@ public:
|
|||||||
adjustWidthToContents = false;
|
adjustWidthToContents = false;
|
||||||
showPreviousAndNextButtons = false;
|
showPreviousAndNextButtons = false;
|
||||||
minimumContentsLength = 8;
|
minimumContentsLength = 8;
|
||||||
|
maximumMenuContentsLength = 40;
|
||||||
enableEditableContent = false;
|
enableEditableContent = false;
|
||||||
minimumWidth = -1;
|
minimumWidth = -1;
|
||||||
iconSize = QSize(14, 14);
|
iconSize = QSize(14, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool adjustWidthToContents;
|
bool adjustWidthToContents;
|
||||||
bool showPreviousAndNextButtons;
|
bool showPreviousAndNextButtons;
|
||||||
int minimumContentsLength; // The length of string to adjust to if adjustWidthToContents = false.
|
int minimumContentsLength; // The length of string to adjust to if adjustWidthToContents = false.
|
||||||
// Set to <= 0 to ignore and use AdjustToContentsOnFirstShow instead
|
// Set to <= 0 to ignore and use AdjustToContentsOnFirstShow instead
|
||||||
|
int maximumMenuContentsLength;
|
||||||
bool enableEditableContent;
|
bool enableEditableContent;
|
||||||
int minimumWidth;
|
int minimumWidth;
|
||||||
QString placeholderText;
|
QString placeholderText;
|
||||||
|
Loading…
Reference in New Issue
Block a user