Gui: add function to determine size that a quantity spin box would need to display a certain text
This commit is contained in:
@@ -785,6 +785,23 @@ void QuantitySpinBox::stepBy(int steps)
|
||||
selectNumber();
|
||||
}
|
||||
|
||||
QSize QuantitySpinBox::sizeForText(const QString& txt) const
|
||||
{
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
int h = lineEdit()->sizeHint().height();
|
||||
int w = QtTools::horizontalAdvance(fm, txt);
|
||||
|
||||
w += 2; // cursor blinking space
|
||||
w += iconHeight;
|
||||
|
||||
QStyleOptionSpinBox opt;
|
||||
initStyleOption(&opt);
|
||||
QSize hint(w, h);
|
||||
QSize size = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)
|
||||
.expandedTo(QApplication::globalStrut());
|
||||
return size;
|
||||
}
|
||||
|
||||
QSize QuantitySpinBox::sizeHint() const
|
||||
{
|
||||
Q_D(const QuantitySpinBox);
|
||||
|
||||
Reference in New Issue
Block a user