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);
|
||||
|
||||
@@ -121,6 +121,8 @@ public:
|
||||
virtual QValidator::State validate(QString &input, int &pos) const;
|
||||
virtual void fixup(QString &str) const;
|
||||
|
||||
/// This is a helper function to determine the size this widget requires to fully display the text
|
||||
QSize sizeForText(const QString&) const;
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
bool event(QEvent *event);
|
||||
|
||||
Reference in New Issue
Block a user