Qt:Документация 4.3.2/qheaderview

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QHeaderView Class Reference
[модуль QtGui ]

The QHeaderView class provides a header row or header column for item views. More...

 #include <QHeaderView>

Inherits QAbstractItemView.

[править] Открытые типы

  • enum ResizeMode { Interactive, Fixed, Stretch, ResizeToContents, Custom }

[править] Свойства

  • 14 свойства унаследованных от QAbstractItemView
  • 2 свойства унаследованных от QAbstractScrollArea
  • 6 свойства унаследованных от QFrame
  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 52 открытых функций унаследованных от QAbstractItemView
  • 15 открытых функций унаследованных от QAbstractScrollArea
  • 13 открытых функций унаследованных от QFrame
  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Открытые слоты

  • 9 открытых слотов унаследованных от QAbstractItemView
  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject

[править] Сигналы

  • 6 сигнала унаследованных от QAbstractItemView
  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject

[править] Защищенные функции

  • 33 защищенных функций унаследованных от QAbstractItemView
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

[править] Защищенные слоты

  • 8 защищенных слотов унаследованных от QAbstractItemView
  • 1 защищенный слот унаследованный от QAbstractScrollArea
  • 1 защищенный слот унаследованный от QWidget

[править] Дополнительные унаследованные члены

  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject

[править] Подробное описание

The QHeaderView class provides a header row or header column for item views.

A QHeaderView displays the headers used in item views such as the QTableView and QTreeView classes. It takes the place of the QHeader class previously used for the same purpose, but uses the Qt's model/view architecture for consistency with the item view classes.

The QHeaderView class is one of the Model/View Classes and is part of Qt's model/view framework.

The header gets the data for each section from the model using the QAbstractItemModel::headerData() function. You can set the data by using QAbstractItemModel::setHeaderData().

Each header has an orientation() and a number of sections, given by the count() function. A section refers to a part of the header - either a row or a column, depending on the orientation.

Sections can be moved and resized using moveSection() and resizeSection(); they can also be hidden and shown with hideSection() and showSection().

Each section of a header is described by a section ID, specified by its section(), and can be located at a particular visualIndex() in the header. A section can have a sort indicator set with setSortIndicator(); this indicates whether the items in the associated item view will be sorted in the order given by the section.

For a horizontal header the section is equivalent to a column in the model, and for a vertical header the section is equivalent to a row in the model.

[править] Moving Header Sections

A header can be fixed in place, or made movable with setMovable(). It can be made clickable with setClickable(), and has resizing behavior in accordance with setResizeMode().

A header emits sectionMoved() if the user moves a section, sectionResized() if the user resizes a section, and sectionClicked() and sectionHandleDoubleClicked() in response to mouse clicks. A header also emits sectionCountChanged() and sectionAutoResize().

You can identify a section using the logicalIndex() and logicalIndexAt() functions, or by its index position, using the visualIndex() and visualIndexAt() functions. The visual index will change if a section is moved, but the logical index will not change.

[править] Appearance

QTableWidget and QTableView create default headers. If you want the headers to be visible, you can use setVisible().

Note: Each header renders the data for each section itself, and does not rely on a delegate. As a result, calling a header's setItemDelegate() function will have no effect.

See also Model/View Programming, QListView, QTableView, and QTreeView.


[править] Описание типов членов

[править]
enum QHeaderView::ResizeMode

The resize mode specifies the behavior of the header sections. It can be set on the entire header view or on individual sections using setResizeMode().


Constant Value Description
QHeaderView::Interactive 0 The user can resize the section. The section can also be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize. (See also cascadingSectionResizes.)
QHeaderView::Fixed 2 The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize.
QHeaderView::Stretch 1 QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.
QHeaderView::ResizeToContents 3 QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2)

The following values are obsolete:


Constant Value Description
QHeaderView::Custom Fixed Use Fixed instead.

See also setResizeMode(), stretchLastSection, and minimumSectionSize.


[править] Описание свойств

[править]
cascadingSectionResizes : bool

This property holds whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size.

This property only affects sections that have Interactive as the resize mode.

The default value is false.

This property was introduced in Qt 4.2.

Функции доступа:

  • bool cascadingSectionResizes () const
  • void setCascadingSectionResizes ( bool enable )

See also setResizeMode().

[править]
defaultAlignment : Qt::Alignment

This property holds the default alignment of the text in each header section.

This property was introduced in Qt 4.1.

Функции доступа:

  • Qt::Alignment defaultAlignment () const
  • void setDefaultAlignment ( Qt::Alignment alignment )

[править]
defaultSectionSize : int

This property holds the default size of the header sections before resizing.

This property only affects sections that have Interactive or Fixed as the resize mode.

Функции доступа:

  • int defaultSectionSize () const
  • void setDefaultSectionSize ( int size )

See also setResizeMode() and minimumSectionSize.

[править]
highlightSections : bool

This property holds whether the sections containing selected items are highlighted.

Функции доступа:

  • bool highlightSections () const
  • void setHighlightSections ( bool highlight )

[править]
minimumSectionSize : int

This property holds the minimum size of the header sections.

The minimum section size is the smallest section size allowed. If the minimum section size is set to -1, QHeaderView will use the maximum of the global strut or the font metrics size.

This property is honored by all resize modes.

This property was introduced in Qt 4.2.

Функции доступа:

  • int minimumSectionSize () const
  • void setMinimumSectionSize ( int size )

See also setResizeMode() and defaultSectionSize.

[править]
showSortIndicator : bool

This property holds whether the sort indicator is shown.

Функции доступа:

  • bool isSortIndicatorShown () const
  • void setSortIndicatorShown ( bool show )

See also setClickable().

[править]
stretchLastSection : bool

This property holds whether the last visible section in the header takes up all the available space.

The default value is false.

Note: The horizontal headers provided by QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header.

Also note: If the value is set to true, this property will override the resize mode set on the last section in the header.

Функции доступа:

  • bool stretchLastSection () const
  • void setStretchLastSection ( bool stretch )

See also setResizeMode().


[править] Описание функций-членов

[править]
QHeaderView::QHeaderView ( Qt::Orientation orientation, QWidget * parent = 0 )

Creates a new generic header with the given orientation and parent.

[править]
QHeaderView::~QHeaderView () [virtual]

Destroys the header.

[править]
int QHeaderView::count () const

Returns the number of sections in the header.

See also sectionCountChanged() and length().

[править]
void QHeaderView::geometriesChanged () [signal]

This signal is emitted when the header geometries has changed.

This function was introduced in Qt 4.2.

[править]
void QHeaderView::headerDataChanged ( Qt::Orientation orientation, int logicalFirst, int logicalLast ) [slot]

Updates the changed header sections with the given orientation, from logicalFirst to logicalLast inclusive.

[править]
int QHeaderView::hiddenSectionCount () const

Returns the number of sections in the header that has been hidden.

This function was introduced in Qt 4.1.

See also setSectionHidden() and isSectionHidden().

[править]
void QHeaderView::hideSection ( int logicalIndex )

Hides the section specified by logicalIndex.

See also showSection(), isSectionHidden(), hiddenSectionCount(), and setSectionHidden().

[править]
int QHeaderView::horizontalOffset () const [virtual protected]

Returns the horizontal offset of the header. This is 0 for vertical headers.

Reimplemented from QAbstractItemView.

See also offset().

[править]
void QHeaderView::initStyleOption ( QStyleOptionHeader * option ) const [protected]

Initialize option with the values from this QHeaderView. This method is useful for subclasses when they need a QStyleOptionHeader, but don't want to fill in all the information themselves.

See also QStyleOption::initFrom().

[править]
bool QHeaderView::isClickable () const

Returns true if the header is clickable; otherwise returns false. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.

See also setClickable().

[править]
bool QHeaderView::isMovable () const

Returns true if the header can be moved by the user; otherwise returns false.

See also setMovable().

[править]
bool QHeaderView::isSectionHidden ( int logicalIndex ) const

Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.

See also hideSection(), showSection(), setSectionHidden(), and hiddenSectionCount().

[править]
int QHeaderView::length () const

Returns the length along the orientation of the header.

See also sizeHint(), setResizeMode(), and offset().

[править]
int QHeaderView::logicalIndex ( int visualIndex ) const

Returns the logicalIndex for the section at the given visualIndex position, or -1 otherwise.

See also visualIndex() and sectionPosition().

[править]
int QHeaderView::logicalIndexAt ( int position ) const

Returns the section that covers the given position in the viewport.

See also visualIndexAt() and isSectionHidden().

[править]
int QHeaderView::logicalIndexAt ( int x, int y ) const

This is an overloaded member function, provided for convenience.

Returns the logical index of the section at the given coordinate. If the header is horizontal x will be used, otherwise y will be used to find the logical index.

[править]
int QHeaderView::logicalIndexAt ( const QPoint & pos ) const

This is an overloaded member function, provided for convenience.

Returns the logical index of the section at the position given in pos. If the header is horizontal the x-coordinate will be used to find the logical index; otherwise the y-coordinate will be used.

See also sectionPosition().

[править]
void QHeaderView::moveSection ( int from, int to )

Moves the section at visual index from to occupy visual index to.

See also sectionsMoved().

[править]
int QHeaderView::offset () const

Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel.

See also setOffset().

[править]
Qt::Orientation QHeaderView::orientation () const

Returns the orientation of the header.

See also Qt::Orientation.

[править]
void QHeaderView::paintSection ( QPainter * painter, const QRect & rect, int logicalIndex ) const [virtual protected]

Paints the section specified by the given logicalIndex, using the given painter and rect.

You normally would not need to use this function.

[править]
ResizeMode QHeaderView::resizeMode ( int logicalIndex ) const

Returns the resize mode that applies to the section specified by the given logicalIndex.

See also setResizeMode().

[править]
void QHeaderView::resizeSection ( int logicalIndex, int size )

Resizes the section specified by logicalIndex to the size measured in pixels.

See also sectionResized(), resizeMode(), and sectionSize().

[править]
void QHeaderView::resizeSections ( QHeaderView::ResizeMode mode )

Resizes the sections according to the given mode, ignoring the current resize mode.

See also resizeMode() and sectionResized().

[править]
void QHeaderView::resizeSections () [protected slot]

This is an overloaded member function, provided for convenience.

Resizes the sections according to their size hints. You should not normally need to call this function.

[править]
bool QHeaderView::restoreState ( const QByteArray & state )

Restores the state of this header view. This function returns true if the state was restored, otherwise returns false.

This function was introduced in Qt 4.3.

See also saveState().

[править]
QByteArray QHeaderView::saveState () const

Saves the current state of this header view.

To restore the saved state, pass the return value to restoreState().

This function was introduced in Qt 4.3.

See also restoreState().

[править]
void QHeaderView::sectionAutoResize ( int logicalIndex, QHeaderView::ResizeMode mode ) [signal]

This signal is emitted when a section is automatically resized. The section's logical index is specified by logicalIndex, and the resize mode by mode.

See also setResizeMode() and stretchLastSection().

[править]
void QHeaderView::sectionClicked ( int logicalIndex ) [signal]

This signal is emitted when a section is clicked. The section's logical index is specified by logicalIndex.

Note that the sectionPressed signal will also be emitted.

See also setClickable() and sectionPressed().

[править]
void QHeaderView::sectionCountChanged ( int oldCount, int newCount ) [signal]

This signal is emitted when the number of sections changes; i.e. when sections are added or deleted. The original count is specified by oldCount, and the new count by newCount.

See also count(), length(), and headerDataChanged().

[править]
void QHeaderView::sectionDoubleClicked ( int logicalIndex ) [signal]

This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex.

See also setClickable().

[править]
void QHeaderView::sectionEntered ( int logicalIndex ) [signal]

This signal is emitted when the cursor moves over the section and the left mouse button is pressed. The section's logical index is specified by logicalIndex.

This function was introduced in Qt 4.3.

See also setClickable() and sectionPressed().

[править]
void QHeaderView::sectionHandleDoubleClicked ( int logicalIndex ) [signal]

This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex.

See also setClickable().

[править]
void QHeaderView::sectionMoved ( int logicalIndex, int oldVisualIndex, int newVisualIndex ) [signal]

This signal is emitted when a section is moved. The section's logical index is specified by logicalIndex, the old index by oldVisualIndex, and the new index position by newVisualIndex.

See also moveSection().

[править]
int QHeaderView::sectionPosition ( int logicalIndex ) const

Returns the section position of the given logicalIndex, or -1 if the section is hidden.

See also sectionViewportPosition().

[править]
void QHeaderView::sectionPressed ( int logicalIndex ) [signal]

This signal is emitted when a section is pressed. The section's logical index is specified by logicalIndex.

See also setClickable().

[править]
void QHeaderView::sectionResized ( int logicalIndex, int oldSize, int newSize ) [signal]

This signal is emitted when a section is resized. The section's logical number is specified by logicalIndex, the old size by oldSize, and the new size by newSize.

See also resizeSection().

[править]
int QHeaderView::sectionSize ( int logicalIndex ) const

Returns the width (or height for vertical headers) of the given logicalIndex.

See also length(), setResizeMode(), and defaultSectionSize().

[править]
QSize QHeaderView::sectionSizeFromContents ( int logicalIndex ) const [virtual protected]

Returns the size of the contents of the section specified by the give logicalIndex.

See also defaultSectionSize().

[править]
int QHeaderView::sectionSizeHint ( int logicalIndex ) const

Returns a suitable size hint for the section specified by logicalIndex.

See also sizeHint(), defaultSectionSize(), minimumSectionSize(), and Qt::SizeHintRole.

[править]
int QHeaderView::sectionViewportPosition ( int logicalIndex ) const

Returns the section viewport position of the given logicalIndex.

If the section is hidden, this function returns an undefined value.

See also sectionPosition() and isSectionHidden().

[править]
void QHeaderView::sectionsAboutToBeRemoved ( const QModelIndex & parent, int logicalFirst, int logicalLast ) [protected slot]

This slot is called when sections are removed from the parent, logicalFirst and logicalLast signify where the sections are removed from. (logicalFirst and logicalLast will be the same if just one section is removed.)

[править]
bool QHeaderView::sectionsHidden () const

Returns true if sections in the header has been hidden; otherwise returns false;

This function was introduced in Qt 4.1.

See also setSectionHidden().

[править]
void QHeaderView::sectionsInserted ( const QModelIndex & parent, int logicalFirst, int logicalLast ) [protected slot]

This slot is called when sections are inserted into the parent, logicalFirst and logicalLast indexes signify where the new sections are inserted.

logicalFirst and logicalLast will be the same if just one section is inserted.

[править]
bool QHeaderView::sectionsMoved () const

Returns true if sections in the header has been moved; otherwise returns false;

See also moveSection().

[править]
void QHeaderView::setClickable ( bool clickable )

If clickable is true, the header will respond to single clicks.

See also isClickable(), sectionClicked(), sectionPressed(), and setSortIndicatorShown().

[править]
void QHeaderView::setMovable ( bool movable )

If movable is true, the header may be moved by the user; otherwise it is fixed in place.

See also isMovable() and sectionMoved().

[править]
void QHeaderView::setOffset ( int offset ) [slot]

Sets the header's offset to offset.

See also offset() and length().

[править]
void QHeaderView::setOffsetToLastSection () [slot]

Sets the offset to make the last section visible.

This function was introduced in Qt 4.2.

See also setOffset(), sectionPosition(), and setOffsetToSectionPosition().

[править]
void QHeaderView::setOffsetToSectionPosition ( int visualIndex ) [slot]

Sets the offset to the start of the section at the given visualIndex.

This function was introduced in Qt 4.2.

See also setOffset() and sectionPosition().

[править]
void QHeaderView::setResizeMode ( ResizeMode mode )

Sets the constraints on how the header can be resized to those described by the given mode.

See also resizeMode(), length(), sectionResized(), and sectionAutoResize().

[править]
void QHeaderView::setResizeMode ( int logicalIndex, ResizeMode mode )

This is an overloaded member function, provided for convenience.

Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode.

[править]
void QHeaderView::setSectionHidden ( int logicalIndex, bool hide )

If hide is true the section specified by logicalIndex is hidden, otherwise the section is shown.

See also isSectionHidden() and hiddenSectionCount().

[править]
void QHeaderView::setSortIndicator ( int logicalIndex, Qt::SortOrder order )

Sets the sort indicator for the section specified by the given logicalIndex in the direction specified by order, and removes the sort indicator from any other section that was showing it.

See also sortIndicatorSection() and sortIndicatorOrder().

[править]
void QHeaderView::showSection ( int logicalIndex )

Shows the section specified by logicalIndex.

See also hideSection(), isSectionHidden(), hiddenSectionCount(), and setSectionHidden().

[править]
QSize QHeaderView::sizeHint () const [virtual]

Returns a suitable size hint for this header.

Reimplemented from QWidget.

See also sectionSizeHint().

[править]
void QHeaderView::sortIndicatorChanged ( int logicalIndex, Qt::SortOrder order ) [signal]

This signal is emitted when the section containing the sort indicator or the order indicated is changed. The section's logical index is specified by logicalIndex and the sort order is specified by order.

This function was introduced in Qt 4.3.

See also setSortIndicator().

[править]
Qt::SortOrder QHeaderView::sortIndicatorOrder () const

Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.

See also setSortIndicator() and sortIndicatorSection().

[править]
int QHeaderView::sortIndicatorSection () const

Returns the logical index of the section that has a sort indicator. By default this is section 0.

See also setSortIndicator(), sortIndicatorOrder(), and setSortIndicatorShown().

[править]
int QHeaderView::stretchSectionCount () const

Returns the number of sections that are set to resize mode stretch. In views this can be used to see if the headerview needs to resize the sections when the view geometry changes.

This function was introduced in Qt 4.1.

See also stretchLastSection and resizeMode().

[править]
void QHeaderView::swapSections ( int first, int second )

Swaps the section at visual index first with the section at visual index second.

This function was introduced in Qt 4.2.

See also moveSection().

[править]
int QHeaderView::verticalOffset () const [virtual protected]

Returns the vertical offset of the header. This is 0 for horizontal headers.

Reimplemented from QAbstractItemView.

See also offset().

[править]
int QHeaderView::visualIndex ( int logicalIndex ) const

Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise. Hidden sections still have valid visual indexes.

See also logicalIndex().

[править]
int QHeaderView::visualIndexAt ( int position ) const

Returns the visual index of the section that covers the given position in the viewport.

See also logicalIndexAt().


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2