The Q3GridView class provides an abstract base for fixed-size grids. 更多...
| 头: | #include <Q3GridView> |
| 继承: | Q3ScrollView |
| Q3GridView (QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0) | |
| ~Q3GridView () | |
| QRect | cellGeometry (int row , int column ) |
| int | cellHeight () const |
| QRect | cellRect () const |
| int | cellWidth () const |
| int | columnAt (int x ) const |
| void | ensureCellVisible (int row , int column ) |
| QSize | gridSize () const |
| int | numCols () const |
| int | numRows () const |
| void | repaintCell (int row , int column , bool erase = true) |
| int | rowAt (int y ) const |
| virtual void | setCellHeight (int) |
| virtual void | setCellWidth (int) |
| virtual void | setNumCols (int) |
| virtual void | setNumRows (int) |
| void | updateCell (int row , int column ) |
| virtual void | dimensionChange (int oldNumRows , int oldNumCols ) |
| virtual void | paintCell (QPainter * p , int row , int col ) = 0 |
| virtual void | paintEmptyArea (QPainter * p , int cx , int cy , int cw , int ch ) |
| virtual void | drawContents (QPainter * p , int cx , int cy , int cw , int ch ) |
The Q3GridView class provides an abstract base for fixed-size grids.
A grid view consists of a number of abstract cells organized in rows and columns. The cells have a fixed size and are identified with a row index and a column index. The top-left cell is in row 0, column 0. The bottom-right cell is in row numRows ()-1, column numCols ()-1.
You can define numRows , numCols , cellWidth and cellHeight . Reimplement the pure virtual function paintCell () to draw the contents of a cell.
采用 ensureCellVisible (), you can ensure a certain cell is visible. With rowAt () 和 columnAt () you can find a cell based on the given x- and y-coordinates.
If you need to monitor changes to the grid's dimensions (i.e. when numRows or numCols is changed), reimplement the dimensionChange () change handler.
Note: the row and column indices are always given in the order, row (vertical offset) then column (horizontal offset). This order is the opposite of all pixel operations, which are given in the order x (horizontal offset), y (vertical offset).
Q3GridView is a very simple abstract class based on Q3ScrollView . It is designed to simplify the task of drawing many cells of the same size in a potentially scrollable canvas. If you need rows and columns with different sizes, use a Q3Table instead. If you need a simple list of items, use a Q3ListBox . If you need to present hierarichal data use a Q3ListView , and if you need random objects at random positions, consider using either a Q3IconView 或 Q3Canvas .
This property holds the height of a grid row.
All rows in a grid view have the same height.
访问函数:
| int | cellHeight () const |
| virtual void | setCellHeight (int) |
另请参阅 cellWidth .
This property holds the width of a grid column.
All columns in a grid view have the same width.
访问函数:
| int | cellWidth () const |
| virtual void | setCellWidth (int) |
另请参阅 cellHeight .
This property holds the number of columns in the grid.
访问函数:
| int | numCols () const |
| virtual void | setNumCols (int) |
另请参阅 numRows .
This property holds the number of rows in the grid.
访问函数:
| int | numRows () const |
| virtual void | setNumRows (int) |
另请参阅 numCols .
Constructs a grid view.
The parent , name 和 Widget 标志 f ,自变量被传递给 Q3ScrollView 构造函数。
Destroys the grid view.
Returns the geometry of cell ( row , column ) in the content coordinate system.
另请参阅 cellRect ().
Returns the geometry of a cell in a cell's coordinate system. This is a convenience function useful in paintCell (). It is equivalent to QRect (0, 0, cellWidth (), cellHeight ()).
另请参阅 cellGeometry ().
Returns the number of the column at position x . x must be given in content coordinates.
另请参阅 rowAt ().
[virtual protected]
void
Q3GridView::
dimensionChange
(
int
oldNumRows
,
int
oldNumCols
)
This change handler is called whenever any of the grid's dimensions change. oldNumRows and oldNumCols contain the old dimensions, numRows () 和 numCols () contain the new dimensions.
[virtual protected]
void
Q3GridView::
drawContents
(
QPainter
*
p
,
int
cx
,
int
cy
,
int
cw
,
int
ch
)
重实现自 Q3ScrollView::drawContents ().
Ensures cell ( row , column ) is visible, scrolling the grid view if necessary.
Returns the size of the grid in pixels.
[pure virtual protected]
void
Q3GridView::
paintCell
(
QPainter
*
p
,
int
row
,
int
col
)
This pure virtual function is called to paint the single cell at ( row , col ) using painter p . The painter must be open when paintCell() is called and must remain open.
The coordinate system is translated so that the origin is at the top-left corner of the cell to be painted, i.e. cell coordinates. Do not scale or shear the coordinate system (or if you do, restore the transformation matrix before you return).
The painter is not clipped by default in order to get maximum efficiency. If you want clipping, use
p->setClipRect(cellRect(), QPainter::CoordPainter); //... your drawing code p->setClipping(false);
[virtual protected]
void
Q3GridView::
paintEmptyArea
(
QPainter
*
p
,
int
cx
,
int
cy
,
int
cw
,
int
ch
)
This function fills the cw pixels wide and ch pixels high rectangle starting at position ( cx , cy ) with the background color using the painter p .
paintEmptyArea() is invoked by drawContents () to erase or fill unused areas.
Repaints cell ( row , column ).
若 erase is true, Qt erases the area of the cell before the paintCell () call; otherwise no erasing takes place.
另请参阅 QWidget::repaint ().
Returns the number of the row at position y . y must be given in content coordinates.
另请参阅 columnAt ().
Updates cell ( row , column ).
另请参阅 QWidget::update ().