Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

Q3TableItem Class

TheQ3TableItem class provides the cell content forQ3Table cells.More...

Header:#include <Q3TableItem>
Inherited By:

Q3CheckTableItem andQ3ComboTableItem

Public Types

enumEditType { Always, WhenCurrent, OnTyping, Never }

Public Functions

Q3TableItem(Q3Table * table, EditType et)
Q3TableItem(Q3Table * table, EditType et, const QString & text)
Q3TableItem(Q3Table * table, EditType et, const QString & text, const QPixmap & p)
virtual~Q3TableItem()
virtual intalignment() const
intcol() const
intcolSpan() const
virtual QWidget *createEditor() const
EditTypeeditType() const
boolisEnabled() const
boolisReplaceable() const
virtual QStringkey() const
virtual voidpaint(QPainter * p, const QColorGroup & cg, const QRect & cr, bool selected)
virtual QPixmappixmap() const
introw() const
introwSpan() const
virtual intrtti() const
virtual voidsetCol(int c)
virtual voidsetContentFromEditor(QWidget * w)
virtual voidsetEnabled(bool b)
virtual voidsetPixmap(const QPixmap & p)
virtual voidsetReplaceable(bool b)
virtual voidsetRow(int r)
virtual voidsetSpan(int rs, int cs)
virtual voidsetText(const QString & str)
virtual voidsetWordWrap(bool b)
virtual QSizesizeHint() const
Q3Table *table() const
virtual QStringtext() const
boolwordWrap() const

Detailed Description

TheQ3TableItem class provides the cell content forQ3Table cells.

For many applications Q3TableItems are ideal for presenting and editing the contents ofQ3Table cells. In situations where you need to create very large tables you may prefer an alternative approach to using Q3TableItems: see the notes on large tables.

AQ3TableItem contains a cell's data, by default, a string and a pixmap. The table item also holds the cell's display size and how the data should be aligned. The table item specifies the cell'sEditType and the editor used for in-place editing (by default aQLineEdit). If you want checkboxes useQ3CheckTableItem, and if you want comboboxes useQ3ComboTableItem. TheEditType (set in the constructor) determines whether the cell's contents may be edited.

If a pixmap is specified it is displayed to the left of any text. You can change the text or pixmap withsetText() andsetPixmap() respectively. For text you can usesetWordWrap().

When sorting table items thekey() function is used; by default this returns the table item'stext(). Reimplementkey() to customize how your table items will sort.

Table items are inserted into a table usingQ3Table::setItem(). If you insert an item into a cell that already contains a table item the original item will be deleted.

Example:

for (int row=0; row< table->numRows(); row++) {for (int col=0; col< table->numCols(); col++) {        table->setItem(row, col,newQ3TableItem(table,Q3TableItem::WhenCurrent,QString::number(row* col)));    }}

You can move a table item from one cell to another, in the same or a different table, usingQ3Table::takeItem() andQ3Table::setItem() but see alsoQ3Table::swapCells().

Table items can be deleted with delete in the standard way; the table and cell will be updated accordingly.

Note, that if you have a table item that is not currently in a table then anything you do to that item other than insert it into a table will result in undefined behaviour.

ReimplementcreateEditor() andsetContentFromEditor() if you want to use your own widget instead of aQLineEdit for editing cell contents. Reimplementpaint() if you want to display custom content.

It is important to ensure that your custom widget can accept the keyboard focus, so that the user can use the tab key to navigate the table as normal. Therefore, if the widget returned bycreateEditor() does not itself accept the keyboard focus, it is necessary to nominate a child widget to do so on its behalf. For example, aQHBox with two childQLineEdit widgets may use one of them to accept the keyboard focus:

QWidget* MyTableItem::createEditor()const{QHBox* hbox=newQHBox(table()->viewport());    hbox->setFocusProxy(newQLineEdit(hbox));newQLineEdit(hbox);return hbox;}

By default, table items may be replaced by new Q3TableItems during the lifetime of aQ3Table. Therefore, if you create your own subclass ofQ3TableItem, and you want to ensure that this does not happen, you must callsetReplaceable(false) in the constructor of your subclass.

Table Items

See alsoQ3CheckTableItem andQ3ComboTableItem.

Member Type Documentation

enum Q3TableItem::EditType

This enum is used to define whether a cell is editable or read-only (in conjunction with other settings), and how the cell should be displayed.

ConstantValueDescription
Q3TableItem::Always3The cell alwayslooks editable.

Using this EditType ensures that the editor created withcreateEditor() (by default aQLineEdit) is always visible. This has implications for the alignment of the content: the default editor aligns everything (even numbers) to the left whilst numerical values in the cell are by default aligned to the right.

If a cell with the edit typeAlways looks misaligned you could reimplementcreateEditor() for these items.

ConstantValueDescription
Q3TableItem::WhenCurrent2The celllooks editable only when it has keyboard focus (seeQ3Table::setCurrentCell()).
Q3TableItem::OnTyping1The celllooks editable only when the user types in it or double-clicks it. It resembles theWhenCurrent functionality but is, perhaps, nicer.

TheOnTyping edit type is the default whenQ3TableItem objects are created by the convenience functionsQ3Table::setText() andQ3Table::setPixmap().

ConstantValueDescription
Q3TableItem::Never0The cell is not editable.

The cell is actually editable only ifQ3Table::isRowReadOnly() is false for its row,Q3Table::isColumnReadOnly() is false for its column, andQ3Table::isReadOnly() is false.

Q3ComboTableItems have an isEditable() property. This property is used to indicate whether the user may enter their own text or are restricted to choosing one of the choices in the list. Q3ComboTableItems may be interacted with only if they are editable in accordance with their EditType as described above.

Member Function Documentation

Q3TableItem::Q3TableItem(Q3Table * table,EditType et)

Creates a table item that is a child of tabletable with no text. The item has theEditTypeet.

The table item will use aQLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table withQ3Table::setItem().

The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.

Q3TableItem::Q3TableItem(Q3Table * table,EditType et, constQString & text)

Creates a table item that is a child of tabletable with texttext. The item has theEditTypeet.

The table item will use aQLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table withQ3Table::setItem().

The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.

Q3TableItem::Q3TableItem(Q3Table * table,EditType et, constQString & text, constQPixmap & p)

Creates a table item that is a child of tabletable with texttext and pixmapp. The item has theEditTypeet.

The table item will display the pixmap to the left of the text. It will use aQLineEdit for editing the text, will not word-wrap and will occupy a single cell. Insert the table item into a table withQ3Table::setItem().

The table takes ownership of the table item, so a table item should not be inserted in more than one table at a time.

[virtual]Q3TableItem::~Q3TableItem()

The destructor deletes this item and frees all allocated resources.

If the table item is in a table (i.e. was inserted with setItem()), it will be removed from the table and the cell it occupied.

[virtual]int Q3TableItem::alignment() const

The alignment function returns how the text contents of the cell are aligned when drawn. The default implementation aligns numbers to the right and any other text to the left.

See alsoQt::Alignment.

int Q3TableItem::col() const

Returns the column where the table item is located. If the cell spans multiple columns, this function returns the left-most column.

See alsorow() andsetCol().

int Q3TableItem::colSpan() const

Returns the column span of the table item, usually 1.

See alsosetSpan() androwSpan().

[virtual]QWidget * Q3TableItem::createEditor() const

This virtual function creates an editor which the user can interact with to edit the cell's contents. The default implementation creates aQLineEdit.

If the function returns 0, the cell is read-only.

The returned widget should preferably be invisible, ideally withQ3Table::viewport() as parent.

If you reimplement this function you'll almost certainly need to reimplementsetContentFromEditor(), and may need to reimplementsizeHint().

See alsoQ3Table::createEditor(),setContentFromEditor(),Q3Table::viewport(), andsetReplaceable().

EditType Q3TableItem::editType() const

Returns the table item's edit type.

This is set when the table item is constructed.

See alsoEditType andQ3TableItem().

bool Q3TableItem::isEnabled() const

Returns true if the table item is enabled; otherwise returns false.

See alsosetEnabled().

bool Q3TableItem::isReplaceable() const

This function returns whether the contents of the cell may be replaced with the contents of another table item. Regardless of this setting, table items that span more than one cell may not have their contents replaced by another table item.

(This differs fromEditType becauseEditType is concerned with whether theuser is able to change the contents of a cell.)

See alsosetReplaceable() andEditType.

[virtual]QString Q3TableItem::key() const

This virtual function returns the key that should be used for sorting. The default implementation returns thetext() of the relevant item.

See alsoQ3Table::setSorting().

[virtual]void Q3TableItem::paint(QPainter * p, constQColorGroup & cg, constQRect & cr,bool selected)

This virtual function is used to paint the contents of an item using the painterp in the rectangular areacr using the color groupcg.

Ifselected is true the cell is displayed in a way that indicates that it is highlighted.

You don't usually need to use this function but if you want to draw custom content in a cell you will need to reimplement it.

The painter passed to this function is translated so that 0, 0 is the top-left corner of the item that is being painted.

Note that the painter is not clipped by default in order to get maximum efficiency. If you want clipping, use

p->setClipRect(table()->cellRect(row, col),QPainter::ClipPainter);//... your drawing codep->setClipping(false);

[virtual]QPixmap Q3TableItem::pixmap() const

Returns the table item's pixmap or a null pixmap if no pixmap has been set.

See alsosetPixmap() andtext().

int Q3TableItem::row() const

Returns the row where the table item is located. If the cell spans multiple rows, this function returns the top-most row.

See alsocol() andsetRow().

int Q3TableItem::rowSpan() const

Returns the row span of the table item, usually 1.

See alsosetSpan() andcolSpan().

[virtual]int Q3TableItem::rtti() const

Returns the Run Time Type Identification value for this table item which for Q3TableItems is 0.

When you create subclasses based onQ3TableItem make sure that each subclass returns a unique rtti() value. It is advisable to use values greater than 1000, preferably large random numbers, to allow for extensions to this class.

See alsoQ3CheckTableItem::rtti() andQ3ComboTableItem::rtti().

[virtual]void Q3TableItem::setCol(int c)

Sets columnc as the table item's column. Usually you will not need to call this function.

If the cell spans multiple columns, this function sets the left-most column and retains the width of the multi-cell table item.

See alsocol(),setRow(), andcolSpan().

[virtual]void Q3TableItem::setContentFromEditor(QWidget * w)

Whenever the content of a cell has been edited by the editorw,Q3Table calls this virtual function to copy the new values into theQ3TableItem.

If you reimplementcreateEditor() and return something that is not aQLineEdit you will need to reimplement this function.

See alsoQ3Table::setCellContentFromEditor().

[virtual]void Q3TableItem::setEnabled(bool b)

Ifb is true, the table item is enabled; ifb is false the table item is disabled.

A disabled item doesn't respond to user interaction.

See alsoisEnabled().

[virtual]void Q3TableItem::setPixmap(constQPixmap & p)

Sets pixmapp to be this item's pixmap.

Note that setPixmap() does not update the cell the table item belongs to. UseQ3Table::updateCell() to repaint the cell's contents.

ForQ3ComboTableItems andQ3CheckTableItems this function has no visible effect.

See alsoQ3Table::setPixmap(),pixmap(), andsetText().

[virtual]void Q3TableItem::setReplaceable(bool b)

Ifb is true it is acceptable to replace the contents of the cell with the contents of anotherQ3TableItem. Ifb is false the contents of the cell may not be replaced by the contents of another table item. Table items that span more than one cell may not have their contents replaced by another table item.

(This differs fromEditType becauseEditType is concerned with whether theuser is able to change the contents of a cell.)

See alsoisReplaceable().

[virtual]void Q3TableItem::setRow(int r)

Sets rowr as the table item's row. Usually you do not need to call this function.

If the cell spans multiple rows, this function sets the top row and retains the height of the multi-cell table item.

See alsorow(),setCol(), androwSpan().

[virtual]void Q3TableItem::setSpan(int rs,int cs)

Changes the extent of theQ3TableItem so that it spans multiple cells coveringrs rows andcs columns. The top left cell is the original cell.

Warning: This function only works if the item has already been inserted into the table using e.g.Q3Table::setItem(). This function also checks to make sure ifrs andcs are within the bounds of the table and returns without changing the span if they are not. In addition swapping, inserting or removing rows and columns that cross Q3TableItems spanning more than one cell is not supported.

See alsorowSpan() andcolSpan().

[virtual]void Q3TableItem::setText(constQString & str)

Changes the table item's text tostr.

Note that setText() does not update the cell the table item belongs to. UseQ3Table::updateCell() to repaint the cell's contents.

See alsoQ3Table::setText(),text(),setPixmap(), andQ3Table::updateCell().

[virtual]void Q3TableItem::setWordWrap(bool b)

Ifb is true, the cell's text will be wrapped over multiple lines, when necessary, to fit the width of the cell; otherwise the text will be written as a single line.

See alsowordWrap(),Q3Table::adjustColumn(), andQ3Table::setColumnStretchable().

[virtual]QSize Q3TableItem::sizeHint() const

This virtual function returns the size a cell needs to show its entire content.

If you subclassQ3TableItem you will often need to reimplement this function.

Q3Table * Q3TableItem::table() const

Returns theQ3Table the table item belongs to.

See alsoQ3Table::setItem() andQ3TableItem().

[virtual]QString Q3TableItem::text() const

Returns the text of the table item or an empty string if there is no text.

To ensure that the current value of the editor is returned,setContentFromEditor() is called:

  1. if the editMode() isAlways, or
  2. if editMode() isnotAlways but the editor of the cell is active and the editor is not aQLineEdit.

This means that text() returns the original text value of the item if the editor is a line edit, until the user commits an edit (e.g. by pressing Enter or Tab) in which case the new text is returned. For other editors (e.g. a combobox)setContentFromEditor() is always called so the currently display value is the one returned.

See alsosetText() andpixmap().

bool Q3TableItem::wordWrap() const

Returns true if word wrap is enabled for the cell; otherwise returns false.

See alsosetWordWrap().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp