Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QSize QAbstractSpinBox::sizeHint (  )  const [virtual, inherited]

Reimplemented from QWidget.

Reimplemented in QDateTimeEdit.

Definition at line 745 of file qabstractspinbox.cpp.

References QWidget::ensurePolished(), QSize::expandedTo(), QWidget::fontMetrics(), QStyleOption::rect, QWidget::rect, QRect::setSize(), QRect::size(), QStyle::sizeFromContents(), QWidget::style(), QStyle::subControlRect(), QString::truncate(), and QFontMetrics::width().

{
    Q_D(const QAbstractSpinBox);
    ensurePolished();

    const QFontMetrics fm(fontMetrics());
    int h = d->edit->sizeHint().height();
    int w = 0;
    QString s;
    s = d->prefix + d->textFromValue(d->minimum) + d->suffix + QLatin1Char(' ');
    s.truncate(18);
    w = qMax(w, fm.width(s));
    s = d->prefix + d->textFromValue(d->maximum) + d->suffix + QLatin1Char(' ');
    s.truncate(18);
    w = qMax(w, fm.width(s));
    if (d->specialValueText.size()) {
        s = d->specialValueText;
        w = qMax(w, fm.width(s));
    }
    w += 2; // cursor blinking space

    QStyleOptionSpinBox opt = d->getStyleOption();
    QSize hint(w, h);
    QSize extra(35, 6);
    opt.rect.setSize(hint + extra);
    extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
                                            QStyle::SC_SpinBoxEditField, this).size();
    // get closer to final result by repeating the calculation
    opt.rect.setSize(hint + extra);
    extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
                                               QStyle::SC_SpinBoxEditField, this).size();
    hint += extra;

    opt.rect = rect();
    return style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)
        .expandedTo(QApplication::globalStrut());
}


Generated by  Doxygen 1.6.0   Back to index