返回介绍

QGridView Class

发布于 2019-10-04 15:00:34 字数 8845 浏览 1225 评论 0 收藏 0

The QGridView class provides an abstract base for fixed-size grids. More...

#include <qgridview.h>

Inherits QScrollView.

List of all member functions.

Public Members

  • QGridView ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )
  • ~QGridView ()
  • int numRows () const
  • virtual void setNumRows ( int )
  • int numCols () const
  • virtual void setNumCols ( int )
  • int cellWidth () const
  • virtual void setCellWidth ( int )
  • int cellHeight () const
  • virtual void setCellHeight ( int )
  • QRect cellRect () const
  • QRect cellGeometry ( introw, intcolumn )
  • QSize gridSize () const
  • int rowAt ( inty ) const
  • int columnAt ( intx ) const
  • void repaintCell ( introw, intcolumn, boolerase = TRUE )
  • void updateCell ( introw, intcolumn )
  • void ensureCellVisible ( introw, intcolumn )

Properties

  • int cellHeight- the height of a grid row
  • int cellWidth- the width of a grid column
  • int numCols- the number of columns in the grid
  • int numRows- the number of rows in the grid

Protected Members

  • virtual void paintCell ( QPainter*p, introw, intcol ) = 0
  • virtual void paintEmptyArea ( QPainter*p, intcx, intcy, intcw, intch )
  • virtual void dimensionChange ( intoldNumRows, intoldNumCols )

Detailed Description

The QGridView 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 content of a cell.

With ensureCellVisible(), you can ensure a certain cell is visible. With rowAt() and 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, 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).

QGridView is a very simple abstract class based on QScrollView. 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 in different sizes, use a QTable instead. If you need a simple list of items, use a QListBox. If you need to present hierachical data use a QListView, and if you need random objects at random positions, consider using either a QIconView or a QCanvas.

See also Abstract Widget Classes.


Member Function Documentation

QGridView::QGridView ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )

Constructs a grid view.

The parent, name and widget flag, f, arguments are passed to the QScrollView constructor.

QGridView::~QGridView ()

Destroys the grid view.

QRect QGridView::cellGeometry ( introw, intcolumn )

Returns the geometry of cell (row, column) in the content coordinate system.

See also cellRect().

int QGridView::cellHeight () const

Returns the height of a grid row. See the "cellHeight" property for details.

QRect QGridView::cellRect () const

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() ).

See also cellGeometry().

int QGridView::cellWidth () const

Returns the width of a grid column. See the "cellWidth" property for details.

int QGridView::columnAt ( intx ) const

Returns the number of the column at position x. x must be given in content coordinates.

See also rowAt().

void QGridView::dimensionChange ( intoldNumRows, intoldNumCols ) [virtual protected]

This change handler is called whenever any of the grid's dimensions changes. oldNumRows and oldNumCols contain the old dimensions, numRows() and numCols() contain the new dimensions.

void QGridView::ensureCellVisible ( introw, intcolumn )

Ensure cell (row, column) is visible, scrolling the grid view if necessary.

QSize QGridView::gridSize () const

Returns the size of the grid in pixels.

int QGridView::numCols () const

Returns the number of columns in the grid. See the "numCols" property for details.

int QGridView::numRows () const

Returns the number of rows in the grid. See the "numRows" property for details.

void QGridView::paintCell ( QPainter*p, introw, intcol ) [pure virtual protected]

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 );

 

void QGridView::paintEmptyArea ( QPainter*p, intcx, intcy, intcw, intch ) [virtual protected]

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.

void QGridView::repaintCell ( introw, intcolumn, boolerase = TRUE )

Repaints cell (row, column).

If erase is TRUE, Qt erases the area of the cell before the paintCell() call; otherwise no erasing takes place.

See also QWidget::repaint().

int QGridView::rowAt ( inty ) const

Returns the number of the row at position y. y must be given in content coordinates.

See also columnAt().

void QGridView::setCellHeight ( int ) [virtual]

Sets the height of a grid row. See the "cellHeight" property for details.

void QGridView::setCellWidth ( int ) [virtual]

Sets the width of a grid column. See the "cellWidth" property for details.

void QGridView::setNumCols ( int ) [virtual]

Sets the number of columns in the grid. See the "numCols" property for details.

void QGridView::setNumRows ( int ) [virtual]

Sets the number of rows in the grid. See the "numRows" property for details.

void QGridView::updateCell ( introw, intcolumn )

Updates cell (row, column).

See also QWidget::update().


Property Documentation

int cellHeight

This property holds the height of a grid row.

All rows in a grid view have the same height.

See also cellWidth.

Set this property's value with setCellHeight() and get this property's value with cellHeight().

int cellWidth

This property holds the width of a grid column.

All columns in a grid view have the same width.

See also cellHeight.

Set this property's value with setCellWidth() and get this property's value with cellWidth().

int numCols

This property holds the number of columns in the grid.

Set this property's value with setNumCols() and get this property's value with numCols().

See also numRows.

int numRows

This property holds the number of rows in the grid.

Set this property's value with setNumRows() and get this property's value with numRows().

See also numCols.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文