QTableWidget Class Reference


This is the abstract base class of all the table widgets. (details) (complete member list)

#include <qtablew.h>

Inherits QFrame.

Inherited by QListBox and QPopupMenu.

Public Members

Protected Members


Detailed Description

This is the abstract base class of all the table widgets.

It provides table and scrolling functionality along both axes. The behavior of the widget can be finely tuned using setTableFlags(); child classes like QListBox are little more than a call to setTableFlags() and some table content manipulation.


Member Function Documentation

QTableWidget::QTableWidget (QWidget *parent=0, const char *name=0, WFlags f=0)

Create a new table widget. All the arguments are passed to the QFrame constructor.

The Tbl_autoVScrollBar, Tbl_autoHScrollBar and Tbl_clipCellPainting flags are set, all other flags are reset.

setCellHeight() and setCellWidth() are set to 0.

QTableWidget::~QTableWidget ()

Destroys the table and frees all occupied memory.

bool QTableWidget::autoUpdate () const

Returns TRUE if the widget updates itself automatically whenever it has changed in some way (e.g. when a flag has been changed).

See also: setAutoUpdate().

int QTableWidget::cellHeight () const

Returns the height of each row, in pixels. If the rows are different in height, this function returns 0.

See also: setCellHeight(), cellWidth(). Reimplemented in QListBox.

int QTableWidget::cellHeight (long)

Returns the height of row row, in pixels. This function is virtual, and must be reimplemented by subclasses that have varying cell heights.

See also: setCellHeight(), cellWidth().

QRect QTableWidget::cellUpdateRect () const

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

int QTableWidget::cellWidth () const

Returns the width of each column, in pixels. If the columns are different in width, this function returns 0.

See also: setCellWidth(), cellHeight(). Reimplemented in QListBox.

int QTableWidget::cellWidth (long col)

Returns the width of column col, in pixels. This function is virtual, and must be reimplemented by subclasses that have varying cell widths.

See also: setCellWidth(), cellHeight().

void QTableWidget::clearTableFlags (ulong f)

Clears the table flags that are set in f. To clear Tbl_snapToGrid, you do

  t->clearTableFlags( Tbl_snapToGrid );

The default argument is to clear all flags.

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

bool QTableWidget::colIsVisible (long col) const

Returns TRUE if col is at least partially visible.

See also: rowIsVisible().

void QTableWidget::coverCornerSquare (bool b)

Called when both scrollbars are active at the same time. Covers the bottom left corner between the two scrollbars with an empty widget.

void QTableWidget::horSbSliding (long val)

horSbSliding temporarily disables Tbl_snapToHGrid and horSbSlidingDone reenables it. The table internally connects the horizontal scrollbar's sliderMoved() and sliderReleased() signals to these slots.

See also: QScrollBar.

void QTableWidget::horSbSlidingDone ()

horSbSliding temporarily disables Tbl_snapToHGrid and horSbSlidingDone reenables it. The table internally connects the horizontal scrollbar's sliderMoved() and sliderReleased() signals to these slots.

See also: QScrollBar.

void QTableWidget::horSbValue (long val)

Moves the table horizontally to offset val without updating the scrollbar. The table internally connects the horizontal scrollbar's valueChanged() to this slot.

long QTableWidget::lastColVisible () const

Returns the index of the last drawn column. The index of the first column is 0.

If no columns can be drawn it returns -1. This can happen if the widget is too narrow for the first column and Tbl_cutCellsH is set.

See also: lastRowVisible().

long QTableWidget::lastRowVisible () const

Returns the index of the last drawn row. The index of the first row is 0.

If no rows can be drawn it returns -1. This can happen if the widget is too small for the first row and Tbl_cutCellsV is set.

See also: lastColumnVisible().

long QTableWidget::leftCell () const

Returns the index of the first column in the table that's visible on the screen.

See also: topCell(), setLeftCell().

long QTableWidget::numCols () const

Returns the number of columns in the table.

See also: numRows(), setNumCols().

long QTableWidget::numRows () const

Returns the number of rows in the table.

See also: numCols(), setNumRows().

void QTableWidget::paintEvent (QPaintEvent *e)

This event handler repaints the widget. It is fairly clever about only repainting the area of the screen that needs it.

void QTableWidget::repaint (bool erase)

Repaints the widget's contents. If erase is TRUE, the widget is cleared to the background color first.

See also: repaintEvent().

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

Repaints part of the widget's contents. The (w,h) pixels big rectangle at (x,y) is repainted, and the rest of the widget is left alone. If erase is TRUE, the widget is cleared to the background color first.

See also: repaintEvent().

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

Repaints the table. If erase is TRUE, the window is cleared to the background color/pixmap first.

QTableWidget is at present the only widget that reimplements repaint(). It does this because by clearing and then repainting one cell at at time, it makes the screen flicker less than it would normally.

void QTableWidget::resizeEvent (QResizeEvent *e)

This event handler handles resizing of the widget.

The scroll bars are moved and cells repainted as necessary.

bool QTableWidget::rowIsVisible (long row) const

Returns TRUE if row is at least partially visible.

See also: colIsVisible().

void QTableWidget::setAutoUpdate (bool b)

If b is TRUE (this is the default) then the widget will update itself automatically whenever it has changed in some way (e.g. when a flag has been changed).

If b is FALSE, the widget won't.

See also: autoUpdate().

void QTableWidget::setBackgroundColor (const QColor &c)

Reimplemented from QWidget, sets the background colors of the scrollbars and the corner square.

void QTableWidget::setCellHeight (int cH)

Sets the height in pixels of the individual cells. Setting it to zero means that the height of rows in the table vary. When set to 0 (this is the default) QTableWidget will call the virtual function cellHeight() to fetch the height.

See also: cellHeight(), cellWidth(), setCellWidth(), totalHeight(), numRows().

void QTableWidget::setCellWidth (int cW)

Sets the width in pixels of the individual cells. Setting it to zero means that the width of columns in the table vary. When set to 0 (this is the default) QTableWidget will call the virtual function cellWidth() to fetch the width.

See also: cellHeight(), setCellHeight(), cellWidth(), totalWidth(), numCols().

void QTableWidget::setLeftCell (long col)

This slot scrolls the table such that col becomes the leftmost column.

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

void QTableWidget::setNumCols (long cols)

Sets the number of columns of the table to cols. The number must be positive.

The table will repaint itself automatically if autoUpdate() is set.

See also: numCols(), numRows(), setNumRows(), setAutoUpdate(), autoUpdate().

void QTableWidget::setNumRows (long rows)

Sets the number of rows of the table to rows. The number must be positive.

The table will repaint itself automatically if autoUpdate is set.

See also: numCols(), setNumCols(), numRows(), setAutoUpdate(), autoUpdate().

void QTableWidget::setOffset (long x, long y, bool updateScrBars = TRUE)

This slot scrolls the table such that (x,y) becomes the top left pixel. The interaction with Tbl_snapTo*Grid is tricky. If updateScrBars is TRUE, the scrollbars are updated.

See also: setTopLeftCell(), setXOffset(), setYOffset().

void QTableWidget::setPalette (const QPalette &p)

Reimplemented from QWidget, sets the palette of the scrollbars and the corner square.

void QTableWidget::setTableFlags (ulong f)

Sets the table flags to f. If a flag setting changes the appearance of the table it will be repainted 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 scrollbar.
Tbl_hScrollBar
The table has a horizontal scrollbar.
Tbl_autoVScrollBar
The table has a vertical scrollbar if and only if the contents are taller than the window.
Tbl_autoHScrollBar
The table has a horizontal scrollbar if and only if the contents are wider than the window.
Tbl_autoScrollBars
The union of the previous two flags.
Tbl_clipCellPainting
The table uses QPainter::clipRect() to make sure that paintCell() will not be able to draw outside the cell boundaries, at the cost of some speed.
Tbl_cutCellsV
The table will never show part of a cell at the bottom of the table; if there isn't space for all of a cell the space will be left blank.
Tbl_cutCellsH
The table will never show part of a cell at the right side of the table; if there isn't space for all of a cell the space will be left blank.
Tbl_cutCells
The union of the previous two flags.
Tbl_scrollLastHCell
When scrolling horizontally, scroll the last cell leftward until it is the only cell visible in its row. If this flag is not set, scrolling will stop as soon as the last cell is completely visible.
Tbl_scrollLastVCell
When scrolling vertically, scroll the last cell upward until it is the only cell visible in its column. If this flag is not set, scrolling will stop as soon as the last cell is completely visible.
Tbl_scrollLastCell
The union of the previous two flags.
Tbl_smoothHScrolling
The table will scroll as smooth as possible when scrolling horizontally. When this flag is not set scrolling will be done one cell at a time.
Tbl_smoothVScrolling
The table will scroll as smooth as possible when scrolling vertically. When this flag is not set scrolling will be done one cell at a time.
Tbl_smoothScrolling
The union of of previous two flags.
Tbl_snapToHGrid
Except when not actually scrolling, the leftmost column shown snap to the leftmost edge of the window.
Tbl_snapToVGrid
Except when not actually scrolling, the top line will snap to the top edge of the window.
Tbl_snapToGrid
The union of the previous two flags.

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

  t->setTableFlags( Tbl_smoothScrolling | Tbl_autoScrollBars );

See also: tableFlags().

void QTableWidget::setTopCell (long row)

This slot scrolls the table such that row becomes the top row.

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

void QTableWidget::setTopLeftCell (long row, long col)

Scrolls the table such that the cell at row row and colum col becomes the top left cell shown.

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

void QTableWidget::setXOffset (long x)

This slot scrolls the table such that x becomes the leftmost pixel. The interaction with Tbl_snapToHGrid is tricky.

See also: setLeftCell(), setYOffset(), setOffset().

void QTableWidget::setYOffset (long y)

This slot scrolls the table such that y becomes the top pixel. The interaction with Tbl_snapToVGrid is tricky.

See also: setTopCell(), setXOffset(), setOffset().

void QTableWidget::setupPainter (QPainter *)

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.

The default implementation does nothing.

void QTableWidget::show ()

Reimplemented from QWidget::show().

void QTableWidget::snapToGrid (bool horizontal, bool vertical)

Scroll the widget to a position such that:

If horizontal is TRUE, the leftmost column shown fits snugly with the left edge of the window.

If vertical is TRUE, the top row shown fits snugly with the top of the window.

You can achieve the same effect automatically by setting any of the Tbl_snapTo*Grid table flags.

ulong QTableWidget::tableFlags () const

Returns the union of the table flags that are currently in effect.

See also: setTableFlags().

bool QTableWidget::testTableFlag (ulong f) const

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

See also: setTableFlags().

long QTableWidget::topCell () const

Returns the index of the first line in the table that's visible on the screen.

See also: leftCell(), setTopCell().

long QTableWidget::totalHeight ()

Returns the total height of the table in pixels. This function is virtual and should be reimplmented in subclasses that have varying cell heights and a non-trivial cellHeight() function or a large amount of rows in the table.

See also: cellHeight().

long QTableWidget::totalWidth ()

Returns the total witdth of the table in pixels. This function is virtual and should be reimplmented in subclasses that have varying cell heights and a non-trivial cellHeight() function or a large amount of rows in the table.

See also: cellWidth().

void QTableWidget::updateCell (long row, long col, bool erase=TRUE)

If the cell at row row, column col is visible, repaints that cell. If erase is TRUE, the relevant part of the window will be cleared to the background color/pixmap before the contents are repainted.

void QTableWidget::verSbSliding (long val)

This slot scrolls the table smoothly vertically even if Tbl_snapToVGrid is set. The table connects this to the vertical scrollbar's sliderMoved() signal.

See also: QScrollBar.

void QTableWidget::verSbSlidingDone ()

The table connects this to the vertical scrollbar's sliderReleased() signal.

void QTableWidget::verSbValue (long val)

Moves the table vertically to offset val without updating the scrollbar. The table internally connects the vertical scrollbar's valueChanged() to this slot.

QRect QTableWidget::windowRect () const

Returns the rectangle which is the actual table, in the widget's own coordinate system. Somewhat similar to clientRect(), but doesn't include any frames.

long QTableWidget::xOffset () const

Returns the coordinate in pixels of the table which is currently on the left edge of the shown part.

See also: yOffset(), the setXOffset() slot and leftCell().

long QTableWidget::yOffset () const

Returns the coordinate in pixels of the table which is currently on the top edge of the shown part.

See also: xOffset(), the setYOffset() slot and topCell().


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech