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

QSize QToolButton::sizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 352 of file qtoolbutton.cpp.

References QWidget::ensurePolished(), QWidget::fontMetrics(), QSize::height(), QStyleOptionToolButton::iconSize, QStyle::pixelMetric(), QStyleOption::rect, QRect::setHeight(), QSize::setWidth(), QFontMetrics::size(), QStyle::sizeFromContents(), QWidget::style(), QAbstractButton::text, QStyleOptionToolButton::toolButtonStyle, QSize::width(), and QFontMetrics::width().

Referenced by minimumSizeHint().

{
    Q_D(const QToolButton);
    ensurePolished();

    int w = 0, h = 0;
    QStyleOptionToolButton opt = d->getStyleOption();

    QFontMetrics fm = fontMetrics();
    if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) {
        QSize icon = opt.iconSize;
        w = icon.width();
        h = icon.height();
    }

    if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
        QSize textSize = fm.size(Qt::TextShowMnemonic, text());
        textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2);
        if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
            h += 4 + textSize.height();
            if (textSize.width() > w)
                w = textSize.width();
        } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
            w += 4 + textSize.width();
            if (textSize.height() > h)
                h = textSize.height();
        } else { // TextOnly
            w = textSize.width();
            h = textSize.height();
        }
    }

    opt.rect.setHeight(h); // PM_MenuButtonIndicator depends on the height
    if (d->popupMode == MenuButtonPopup)
        w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);

    return style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this).
            expandedTo(QApplication::globalStrut());
}


Generated by  Doxygen 1.6.0   Back to index