Public Member Functions | Protected Member Functions | Properties | Friends

QxtHeaderView Class Reference
[QxtGui]

An extended QHeaderView with optionally proportional section sizes. More...

#include <qxtheaderview.h>

Collaboration diagram for QxtHeaderView:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QxtHeaderView (Qt::Orientation orientation, QWidget *parent=0)
bool hasProportionalSectionSizes () const
void setProportionalSectionSizes (bool enabled)
int sectionStretchFactor (int logicalIndex) const
void setSectionStretchFactor (int logicalIndex, int factor)

Protected Member Functions

void resizeEvent (QResizeEvent *event)

Properties

bool proportionalSectionSizes

Friends

class QxtHeaderViewPrivate

Detailed Description

An extended QHeaderView with optionally proportional section sizes.

Definition at line 34 of file qxtheaderview.h.


Constructor & Destructor Documentation

QxtHeaderView::QxtHeaderView ( Qt::Orientation  orientation,
QWidget *  parent = 0 
) [explicit]

Constructs a new QxtHeaderView with orientation and parent.

Definition at line 52 of file qxtheaderview.cpp.

References QXT_INIT_PRIVATE.

        : QHeaderView(orientation, parent)
{
    QXT_INIT_PRIVATE(QxtHeaderView);
}

Member Function Documentation

bool QxtHeaderView::hasProportionalSectionSizes (  ) const

Definition at line 68 of file qxtheaderview.cpp.

{
    return qxt_d().proportional;
}
void QxtHeaderView::resizeEvent ( QResizeEvent *  event ) [protected]

Definition at line 106 of file qxtheaderview.cpp.

{
    QHeaderView::resizeEvent(event);
    if (qxt_d().proportional)
    {
        int total = 0;
        for (int i = 0; i < count(); ++i)
            total += qxt_d().factors.value(i, 1);

        int totalSize = 0;
        for (int i = 0; i < count() - 1; ++i)
        {
            qreal factor = qxt_d().factors.value(i, 1) / static_cast<qreal>(total);
            int sectionSize = factor * (orientation() == Qt::Horizontal ? width() : height());
            sectionSize = qMax(minimumSectionSize(), sectionSize);
            resizeSection(i, sectionSize);
            totalSize += sectionSize;
        }
        // avoid rounding errors, give rest to the last section
        resizeSection(count() - 1, width() - totalSize);
    }
}
int QxtHeaderView::sectionStretchFactor ( int  logicalIndex ) const

Returns the stretch factor of the section at logicalIndex.

See also:
setSectionStretchFactor()

Definition at line 88 of file qxtheaderview.cpp.

{
    return qxt_d().factors.value(logicalIndex);
}
void QxtHeaderView::setProportionalSectionSizes ( bool  enabled )

Definition at line 73 of file qxtheaderview.cpp.

{
    if (qxt_d().proportional != enabled)
    {
        qxt_d().proportional = enabled;
        if (enabled)
            setResizeMode(QHeaderView::Fixed);
    }
}
void QxtHeaderView::setSectionStretchFactor ( int  logicalIndex,
int  factor 
)

Sets the stretch factor of the section at logicalIndex.

See also:
sectionStretchFactor()

Definition at line 98 of file qxtheaderview.cpp.

{
    qxt_d().factors.insert(logicalIndex, factor);
}

Friends And Related Function Documentation

friend class QxtHeaderViewPrivate [friend]

Definition at line 37 of file qxtheaderview.h.


Property Documentation

bool QxtHeaderView::proportionalSectionSizes [read, write]

Definition at line 37 of file qxtheaderview.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines