QtTableView Class

Qt 3.0.5

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QtTableView Class Reference
[obsolete]

The QtTableView class provides an abstract base for tables. More...

#include <qttableview.h>

Inherits QFrame.

Inherited by QtMultiLineEdit.

List of all member functions.

Public Members

  • void repaint ( bool erase = TRUE )
  • void repaint ( int x, int y, int w, int h, bool erase = TRUE )
  • void repaint ( const QRect & r, bool erase = TRUE )

Protected Members


Detailed Description

The QtTableView class provides an abstract base for tables.

This class is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

A table view consists of a number of abstract cells organized in rows and columns, and a visible part called a view. The cells are identified with a row index and a column index. The top-left cell is in row 0, column 0.

The behavior of the widget can be finely tuned using setTableFlags(); a typical subclass will consist of little more than a call to setTableFlags(), some table content manipulation and an implementation of paintCell(). Subclasses that need cells with variable width or height must reimplement cellHeight() and/or cellWidth(). Use updateTableSize() to tell QtTableView when the width or height has changed.

When you read this documentation, it is important to understand the distinctions among the four pixel coordinate systems involved.

  1. The cell coordinates. (0,0) is the top-left corner of a cell. Cell coordinates are used by functions such as paintCell().

  2. The table coordinates. (0,0) is the top-left corner of the cell at row 0 and column 0. These coordinates are absolute; that is, they are independent of what part of the table is visible at the moment. They are used by functions such as setXOffset() or maxYOffset().

  3. The widget coordinates. (0,0) is the top-left corner of the widget, including the frame. They are used by functions such as repaint().

  4. The view coordinates. (0,0) is the top-left corner of the view, excluding the frame. This is the least-used coordinate system; it is used by functions such as viewWidth().

It is rather unfortunate that we have to use four different coordinate systems, but there was no alternative to provide a flexible and powerful base class.

Note: The row,column indices are always given in that order, i.e., first the vertical (row), then the horizontal (column). This is the opposite order of all pixel operations, which take first the horizontal (x) and then the vertical (y).

Warning: the functions setNumRows(), setNumCols(), setCellHeight(), setCellWidth(), setTableFlags() and clearTableFlags() may cause virtual functions such as cellWidth() and cellHeight() to be called, even if autoUpdate() is FALSE. This may cause errors if relevant state variables are not initialized.

Warning: Experience has shown that use of this widget tends to cause more bugs than expected and our analysis indicates that the widget's very flexibility is the problem. If QScrollView or QListBox can easily be made to do the job you need, we recommend subclassing those widgets rather than QtTableView. In addition, QScrollView makes it easy to have child widgets inside tables, which QtTableView doesn't support at all.

See also QScrollView and GUI Design Handbook: Table.


Member Function Documentation

QtTableView::QtTableView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) [protected]

Constructs a table view. The parent, name and \f arguments are passed to the QFrame constructor.

The table flags are all cleared (set to 0). Set Tbl_autoVScrollBar or Tbl_autoHScrollBar to get automatic scroll bars and Tbl_clipCellPainting to get safe clipping.

The cell height and cell width are set to 0.

Frame line shapes (QFrame::HLink and QFrame::VLine) are disallowed; see QFrame::setFrameStyle().

Note that the f argument is not table flags but rather widget flags.

QtTableView::~QtTableView () [protected]

Destroys the table view.

bool QtTableView::autoUpdate () const [protected]

Returns TRUE if the view updates itself automatically whenever it is changed in some way.

See also setAutoUpdate().

int QtTableView::cellHeight ( int row ) [virtual protected]

Returns the height of row row in pixels.

This function is virtual and must be reimplemented by subclasses that have variable cell heights. Note that if the total table height changes, updateTableSize() must be called.

See also setCellHeight(), cellWidth() and totalHeight().

int QtTableView::cellHeight () const [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the row height, in pixels. Returns 0 if the rows have variable heights.

See also setCellHeight() and cellWidth().

QRect QtTableView::cellUpdateRect () const [protected]

This function should be called only from the paintCell() function in subclasses. It returns the portion of a cell that actually needs to be updated in cell coordinates. This is useful only for non-trivial paintCell().

int QtTableView::cellWidth ( int col ) [virtual protected]

Returns the width of column col in pixels.

This function is virtual and must be reimplemented by subclasses that have variable cell widths. Note that if the total table width changes, updateTableSize() must be called.

See also setCellWidth(), cellHeight(), totalWidth() and updateTableSize().

int QtTableView::cellWidth () const [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the column width in pixels. Returns 0 if the columns have variable widths.

See also setCellWidth() and cellHeight().

void QtTableView::clearTableFlags ( uint f = ~0 ) [protected]

Clears the table flags that are set in f.

Example (clears a single flag):

    clearTableFlags( Tbl_snapToGrid );
  

The default argument clears all flags.

See also setTableFlags(), testTableFlags() and tableFlags().

bool QtTableView::colIsVisible ( int col ) const [protected]

Returns TRUE if col is at least partially visible.

See also rowIsVisible().

bool QtTableView::colXPos ( int col, int * xPos ) const [protected]

Computes the position in the widget of column col.

Returns TRUE and stores the result in *xPos (in widget coordinates) if the column is visible. Returns FALSE and does not modify *xPos if col is invisible or invalid.

See also rowYPos() and findCol().

int QtTableView::findCol ( int xPos ) const [protected]

Returns the index of the column at position xPos, where xPos is in widget coordinates. Returns -1 if xPos is outside the valid range.

See also findRow() and colXPos().

int QtTableView::findRow ( int yPos ) const [protected]

Returns the index of the row at position yPos, where yPos is in widget coordinates. Returns -1 if yPos is outside the valid range.

See also findCol() and rowYPos().

QScrollBar * QtTableView::horizontalScrollBar () const [protected]

Returns a pointer to the horizontal scroll bar mainly so you can connect() to its signals. Note that the scroll bar works in pixel values; use findCol() to translate to cell numbers.

int QtTableView::lastColVisible () const [protected]

Returns the index of the last (right) column in the view. The index of the first column is 0.

If no columns are visible it returns -1. This can happen if the view is too narrow for the first column and Tbl_cutCellsH is set.

See also lastRowVisible().

int QtTableView::lastRowVisible () const [protected]

Returns the index of the last (bottom) row in the view. The index of the first row is 0.

If no rows are visible it returns -1. This can happen if the view is too small for the first row and Tbl_cutCellsV is set.

See also lastColVisible().

int QtTableView::leftCell () const [protected]

Returns the index of the first column in the table that is visible in the view. The index of the very leftmost column is 0.

See also topCell() and setLeftCell().

int QtTableView::maxColOffset () [protected]

Returns the index of the last column, which may be at the left edge of the view.

Depending on the Tbl_scrollLastHCell flag, this may or may not be the last column.

See also maxXOffset() and maxRowOffset().

int QtTableView::maxRowOffset () [protected]

Returns the index of the last row, which may be at the top edge of the view.

Depending on the Tbl_scrollLastVCell flag, this may or may not be the last row.

See also maxYOffset() and maxColOffset().

int QtTableView::maxViewX () const [protected]

Returns the rightmost pixel of the table view in view coordinates. This excludes the frame and any scroll bar, but includes blank pixels to the right of the visible table data.

See also maxViewY(), viewWidth() and contentsRect.

int QtTableView::maxViewY () const [protected]

Returns the bottom pixel of the table view in view coordinates. This excludes the frame and any scroll bar, but includes blank pixels below the visible table data.

See also maxViewX(), viewHeight() and contentsRect.

int QtTableView::maxXOffset () [protected]

Returns the maximum horizontal offset within the table of the view's left edge in table coordinates.

This is used mainly to set the horizontal scroll bar's range.

See also maxColOffset(), maxYOffset() and totalWidth().

int QtTableView::maxYOffset () [protected]

Returns the maximum vertical offset within the table of the view's top edge in table coordinates.

This is used mainly to set the vertical scroll bar's range.

See also maxRowOffset(), maxXOffset() and totalHeight().

int QtTableView::minViewX () const [protected]

Returns the leftmost pixel of the table view in view coordinates. This excludes the frame and any header.

See also maxViewY(), viewWidth() and contentsRect.

int QtTableView::minViewY () const [protected]

Returns the top pixel of the table view in view coordinates. This excludes the frame and any header.

See also maxViewX(), viewHeight() and contentsRect.

int QtTableView::numCols () const [protected]

Returns the number of columns in the table.

See also numRows() and setNumCols().

int QtTableView::numRows () const [protected]

Returns the number of rows in the table.

See also numCols() and setNumRows().

void QtTableView::paintCell ( QPainter * p, int row, int col ) [pure virtual protected]

This pure virtual function is called to paint the single cell at (row,col) using p, which is 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 and for maximum efficiency. For safety, call setTableFlags(Tbl_clipCellPainting) to enable clipping.

See also paintEvent() and setTableFlags().

Reimplemented in QtMultiLineEdit.

void QtTableView::paintEvent ( QPaintEvent * e ) [virtual protected]

Handles paint events, e, for the table view.

Calls paintCell() for the cells that needs to be repainted.

Reimplemented from QFrame.

void QtTableView::repaint ( int x, int y, int w, int h, bool erase = TRUE )

Repaints the table view directly by calling paintEvent() directly unless updates are disabled.

Erases the view area (x,y,w,h) if erase is TRUE. Parameters (x,y) are in widget coordinates.

If w is negative, it is replaced with width() - x. If h is negative, it is replaced with height() - y.

Doing a repaint() usually is faster than doing an update(), but calling update() many times in a row will generate a single paint event.

At present, QtTableView is the only widget that reimplements repaint(). It does this because by clearing and then repainting one cell at at time, it can make the screen flicker less than it would otherwise.

void QtTableView::repaint ( bool erase = TRUE )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Repaints the entire view.

void QtTableView::repaint ( const QRect & r, bool erase = TRUE )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Replaints rectangle r. If erase is TRUE draws the background using the palette's background.

bool QtTableView::rowIsVisible ( int row ) const [protected]

Returns TRUE if row is at least partially visible.

See also colIsVisible().

bool QtTableView::rowYPos ( int row, int * yPos ) const [protected]

Computes the position in the widget of row row.

Returns TRUE and stores the result in *yPos (in widget coordinates) if the row is visible. Returns FALSE and does not modify *yPos if row is invisible or invalid.

See also colXPos() and findRow().

void QtTableView::scroll ( int xPixels, int yPixels ) [protected]

Moves the visible area of the table right by xPixels and down by yPixels pixels. Both may be negative.

Warning: You might find that QScrollView offers a higher-level of functionality than using QtTableView and this function.

This function is not the same as QWidget::scroll(); in particular, the signs of xPixels and yPixels have the reverse semantics.

See also setXOffset(), setYOffset(), setOffset(), setTopCell() and setLeftCell().

void QtTableView::setAutoUpdate ( bool enable ) [virtual protected]

Sets the auto-update option of the table view to enable.

If enable is TRUE (this is the default), the view updates itself automatically whenever it has changed in some way (for example, when a flag is changed).

If enable is FALSE, the view does NOT repaint itself or update its internal state variables when it is changed. This can be useful to avoid flicker during large changes and is singularly useless otherwise. Disable auto-update, do the changes, re-enable auto-update and call repaint().

Warning: Do not leave the view in this state for a long time (i.e., between events). If, for example, the user interacts with the view when auto-update is off, strange things can happen.

Setting auto-update to TRUE does not repaint the view; you must call repaint() to do this.

See also autoUpdate() and repaint().

Reimplemented in QtMultiLineEdit.

void QtTableView::setCellHeight ( int cellHeight ) [virtual protected]

Sets the height in pixels of the table cells to cellHeight.

Setting it to 0 means that the row height is variable. When set to 0 (this is the default), QtTableView calls the virtual function cellHeight() to get the height.

See also cellHeight(), setCellWidth(), totalHeight() and numRows().

void QtTableView::setCellWidth ( int cellWidth ) [virtual protected]

Sets the width in pixels of the table cells to cellWidth.

Setting it to 0 means that the column width is variable. When set to 0 (this is the default) QtTableView calls the virtual function cellWidth() to get the width.

See also cellWidth(), setCellHeight(), totalWidth() and numCols().

void QtTableView::setLeftCell ( int col ) [virtual protected]

Scrolls the table so that col becomes the leftmost column. The index of the leftmost column is 0.

See also setXOffset(), setTopLeftCell() and setTopCell().

void QtTableView::setNumCols ( int cols ) [virtual protected]

Sets the number of columns of the table to cols (must be non-negative). Does not change leftCell().

The table repaints itself automatically if autoUpdate() is set.

See also numCols(), numRows() and setNumRows().

void QtTableView::setNumRows ( int rows ) [virtual protected]

Sets the number of rows of the table to rows (must be non-negative). Does not change topCell().

The table repaints itself automatically if autoUpdate() is set.

See also numCols(), setNumCols() and numRows().

void QtTableView::setOffset ( int x, int y, bool updateScrBars = TRUE ) [virtual protected]

Scrolls the table so that (x,y) becomes the top-left pixel in the view. Parameters (x,y) are in table coordinates.

The interaction with Tbl_snapTo*Grid is tricky. If updateScrBars is TRUE, the scroll bars are updated.

See also xOffset(), yOffset(), setXOffset(), setYOffset() and setTopLeftCell().

void QtTableView::setTableFlags ( uint f ) [virtual protected]

Sets the table flags to f.

If a flag setting changes the appearance of the table, the table is repainted if - and only if - autoUpdate() is TRUE.

The table flags are mostly single bits, though there are some multibit flags for convenience. Here is a complete list:

Tbl_vScrollBar
- The table has a vertical scroll bar.
Tbl_hScrollBar
- The table has a horizontal scroll bar.
Tbl_autoVScrollBar
- The table has a vertical scroll bar if - and only if - the table is taller than the view.
Tbl_autoHScrollBar
The table has a horizontal scroll bar if - and only if - the table is wider than the view.
Tbl_autoScrollBars
- The union of the previous two flags.
Tbl_clipCellPainting
- The table uses QPainter::setClipRect() to make sure that paintCell() will not draw outside the cell boundaries.
Tbl_cutCellsV
- The table will never show part of a cell at the bottom of the table; if there is not space for all of a cell, the space is left blank.
Tbl_cutCellsH
- The table will never show part of a cell at the right side of the table; if there is not space for all of a cell, the space is left blank.
Tbl_cutCells
- The union of the previous two flags.
Tbl_scrollLastHCell
- When the user scrolls horizontally, let him/her scroll the last cell left until it is at the left edge of the view. If this flag is not set, the user can only scroll to the point where the last cell is completely visible.
Tbl_scrollLastVCell
- When the user scrolls vertically, let him/her scroll the last cell up until it is at the top edge of the view. If this flag is not set, the user can only scroll to the point where the last cell is completely visible.
Tbl_scrollLastCell
- The union of the previous two flags.
Tbl_smoothHScrolling
- The table scrolls as smoothly as possible when the user scrolls horizontally. When this flag is not set, scrolling is done one cell at a time.
Tbl_smoothVScrolling
- The table scrolls as smoothly as possible when scrolling vertically. When this flag is not set, scrolling is done one cell at a time.
Tbl_smoothScrolling
- The union of the previous two flags.
Tbl_snapToHGrid
- Except when the user is actually scrolling, the leftmost column shown snaps to the leftmost edge of the view.
Tbl_snapToVGrid
- Except when the user is actually scrolling, the top row snaps to the top edge of the view.
Tbl_snapToGrid
- The union of the previous two flags.

You can specify more than one flag at a time using bitwise OR.

Example:

    setTableFlags( Tbl_smoothScrolling | Tbl_autoScrollBars );
  

Warning: The cutCells options (Tbl_cutCells, Tbl_cutCellsH and Tbl_cutCellsV) may cause painting problems when scrollbars are enabled. Do not combine cutCells and scrollbars.

See also clearTableFlags(), testTableFlags() and tableFlags().

void QtTableView::setTopCell ( int row ) [virtual protected]

Scrolls the table so that row becomes the top row. The index of the very first row is 0.

See also setYOffset(), setTopLeftCell() and setLeftCell().

void QtTableView::setTopLeftCell ( int row, int col ) [virtual protected]

Scrolls the table so that the cell at row row and colum col becomes the top-left cell in the view. The cell at the extreme top left of the table is at position (0,0).

See also setLeftCell(), setTopCell() and setOffset().

void QtTableView::setXOffset ( int x ) [virtual protected]

Scrolls the table so that x becomes the leftmost pixel in the view. The x parameter is in table coordinates.

The interaction with Tbl_snapToHGrid is tricky.

See also xOffset(), setYOffset(), setOffset() and setLeftCell().

void QtTableView::setYOffset ( int y ) [virtual protected]

Scrolls the table so that y becomes the top pixel in the view. The y parameter is in table coordinates.

The interaction with Tbl_snapToVGrid is tricky.

See also yOffset(), setXOffset(), setOffset() and setTopCell().

void QtTableView::setupPainter ( QPainter * ) [virtual protected]

This virtual function is called before painting of table cells is started. It can be reimplemented by subclasses that want to to set up the painter in a special way and that do not want to do so for each cell.

uint QtTableView::tableFlags () const [protected]

Returns the union of the table flags that are currently set.

See also setTableFlags(), clearTableFlags() and testTableFlags().

bool QtTableView::testTableFlags ( uint f ) const [protected]

Returns TRUE if any of the table flags in f are currently set, otherwise FALSE.

See also setTableFlags(), clearTableFlags() and tableFlags().

int QtTableView::topCell () const [protected]

Returns the index of the first row in the table that is visible in the view. The index of the first row is 0.

See also leftCell() and setTopCell().

int QtTableView::totalHeight () [virtual protected]

Returns the total height of the table in pixels.

This function is virtual and should be reimplemented by subclasses that have variable cell heights and a non-trivial cellHeight() function, or a large number of rows in the table.

The default implementation may be slow for very tall tables.

See also cellHeight() and totalWidth().

int QtTableView::totalWidth () [virtual protected]

Returns the total width of the table in pixels.

This function is virtual and should be reimplemented by subclasses that have variable cell widths and a non-trivial cellWidth() function, or a large number of columns in the table.

The default implementation may be slow for very wide tables.

See also cellWidth() and totalHeight().

void QtTableView::updateCell ( int row, int col, bool erase = TRUE ) [protected]

Repaints the cell at row row, column col if it is inside the view.

If erase is TRUE, the relevant part of the view is cleared to the background color/pixmap before the contents are repainted.

See also visible.

void QtTableView::updateScrollBars () [protected]

Updates the scroll bars' contents and presence to match the table's state. Generally, you should not need to call this.

See also setTableFlags().

void QtTableView::updateTableSize () [protected]

Updates the scroll bars and internal state.

Call this function when the table view's total size is changed; typically because the result of cellHeight() or cellWidth() have changed.

This function does not repaint the widget.

QScrollBar * QtTableView::verticalScrollBar () const [protected]

Returns a pointer to the vertical scroll bar mainly so you can connect() to its signals. Note that the scroll bar works in pixel values; use findRow() to translate to cell numbers.

int QtTableView::viewHeight () const [protected]

Returns the height of the table view, as such, in view coordinates. This does not include any header, scroll bar or frame, but it does include background pixels below the table data.

See also minViewY(), maxViewY(), viewWidth(), contentsRect and viewRect().

QRect QtTableView::viewRect () const [protected]

Returns the rectangle that is the actual table, excluding any frame, in widget coordinates.

int QtTableView::viewWidth () const [protected]

Returns the width of the table view, as such, in view coordinates. This does not include any header, scroll bar or frame, but it does include background pixels to the right of the table data.

See also minViewX(), maxViewX(), viewHeight(), contentsRect and viewRect().

int QtTableView::xOffset () const [protected]

Returns the x coordinate in table coordinates of the pixel that is currently on the left edge of the view.

See also setXOffset(), yOffset() and leftCell().

int QtTableView::yOffset () const [protected]

Returns the y coordinate in table coordinates of the pixel that is currently on the top edge of the view.

See also setYOffset(), xOffset() and topCell().


This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.


Copyright © 2002 TrolltechTrademarks
Qt version 3.0.5