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

QRect QStyle::itemTextRect ( const QFontMetrics metrics,
const QRect rectangle,
int  alignment,
bool  enabled,
const QString text 
) const [virtual, inherited]

Returns the area within the given rectangle in which to draw the provided text according to the specified font metrics and alignment. The enabled parameter indicates whether or not the associated item is enabled.

If the given rectangle is larger than the area needed to render the text, the rectangle that is returned will be offset within rectangle according to the specified alignment. For example, if alignment is Qt::AlignCenter, the returned rectangle will be centered within rectangle. If the given rectangle is smaller than the area needed, the returned rectangle will be the smallest rectangle large enough to render the text.

See also:
Qt::Alignment

Definition at line 418 of file qstyle.cpp.

References QFontMetrics::boundingRect(), QRect::getRect(), QRect::height(), QString::isEmpty(), QRect::setHeight(), QRect::setWidth(), QStyle::styleHint(), and QRect::width().

Referenced by QCheckBox::sizeHint(), QRadioButton::sizeHint(), and QCommonStyle::subElementRect().

{
    QRect result;
    int x, y, w, h;
    rect.getRect(&x, &y, &w, &h);
    if (!text.isEmpty()) {
        result = metrics.boundingRect(x, y, w, h, alignment, text);
        if (!enabled && styleHint(SH_EtchDisabledText)) {
            result.setWidth(result.width()+1);
            result.setHeight(result.height()+1);
        }
    } else {
        result = QRect(x, y, w, h);
    }
    return result;
}


Generated by  Doxygen 1.6.0   Back to index