看了网上相关的一篇文章,还是没弄明白。
http://blog.chinaunix.net/uid-25806493-id-3341558.html —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
QHeaderView
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 Qt3's 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().
Note: Double-clicking on a header to resize a section only applies for visible rows.
A header will emit sectionMoved() if the user moves a section, sectionResized() if the user resizes a section, and sectionClicked() as well assectionHandleDoubleClicked() in response to mouse clicks. A header will also emit 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().
Not all ItemDataRoles will have an effect on a QHeaderView. If you need to draw other roles, you can subclass QHeaderView and reimplement paintEvent(). QHeaderView respects the following item data roles: TextAlignmentRole,
DisplayRole, FontRole, DecorationRole, ForegroundRole, and BackgroundRole.
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.
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Coordinate Systems
For some specialized forms of tables it is useful to be able to convert between row and column indexes and widget coordinates. The rowAt() function provides the y-coordinate within the view of the specified row; the row index can be used to obtain a corresponding y-coordinate with rowViewportPosition(). ThecolumnAt() and columnViewportPosition() functions provide the equivalent conversion operations between x-coordinates and column indexes.