1. 程式人生 > >Qt中文手冊 之 QTableWidgetItem

Qt中文手冊 之 QTableWidgetItem

標頭檔案 #include<QTableWidgetItem>

成員函式

1、QTableWidgetItem::QTableWidgetItem(int type = Type)

  使用指定item型別type構造。

     item的type

QTableWidgetItem::Type 0 預設的型別:視窗部件
QTableWidgetItem::UserType 1000 The minimum value for custom types. Values below UserType are reserved by Qt.

2、QTableWidgetItem::QTableWidgetItem

(const QString & text, int type = Type)

  使用指定文字text 和 type 構造

3、QTableWidgetItem::QTableWidgetItem(const QIcon & icon, const QString & text,int type = Type)

    使用圖示icon和文字text及型別type構造

4、QTableWidgetItem::QTableWidgetItem(const QTableWidgetItem & other)

    複製構造,注意:type()和tableWidget()不復制

5、QBrush QTableWidgetItem::background() const

   返回背景色

6、Qt::CheckState QTableWidgetItem::checkState() const

  返回當前是否選中的狀態:Qt::Unchecked:未選中Qt::Checked:選中等

7、QTableWidgetItem * QTableWidgetItem::clone() const

    複製本項

8、int QTableWidgetItem::column() const

    返回項所在的列,如果不在表中,返回-1

9、[virtual] QVariant

QTableWidgetItem::data(int role) const

    返回給定角色的資料。

   role:

常用的role

Constant Value Description
Qt::DisplayRole 0 The key data to be rendered in the form of text. (QString)
Qt::DecorationRole 1 The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap)
Qt::EditRole 2 The data in a form suitable for editing in an editor. (QString)
Qt::ToolTipRole 3 The data displayed in the item's tooltip. (QString)
Qt::StatusTipRole 4 The data displayed in the status bar. (QString)
Qt::WhatsThisRole 5 The data displayed for the item in "What's This?" mode. (QString)
Qt::SizeHintRole 13 The size hint for the item that will be supplied to views. (QSize)

描述外觀的role

Constant Value Description
Qt::FontRole 6 The font used for items rendered with the default delegate. (QFont)
Qt::TextAlignmentRole 7 The alignment of the text for items rendered with the default delegate. (Qt::AlignmentFlag)
Qt::BackgroundRole 8 The background brush used for items rendered with the default delegate. (QBrush)
Qt::BackgroundColorRole 8 This role is obsolete. Use BackgroundRole instead.
Qt::ForegroundRole 9 The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush)
Qt::TextColorRole 9 This role is obsolete. Use ForegroundRole instead.
Qt::CheckStateRole 10 This role is used to obtain the checked state of an item. (Qt::CheckState)
Qt::InitialSortOrderRole 14 This role is used to obtain the initial sort order of a header view section. (Qt::SortOrder). This role was introduced in Qt 4.8.

擴充套件的role

Constant Value Description
Qt::AccessibleTextRole 11 The text to be used by accessibility extensions and plugins, such as screen readers. (QString)
Qt::AccessibleDescriptionRole 12 A description of the item for accessibility purposes. (QString)

使用者role

Constant Value Description
Qt::UserRole 32 The first role that can be used for application-specific purposes.

10、Qt::ItemFlags QTableWidgetItem::flags() const

     返回專案前的標誌。包括是否被點選、是否被編輯、是否被選中。

11、QFont QTableWidgetItem::font() const

   返回項用的文字的字型

12、QBrush QTableWidgetItem::foreground() const

  返回項的前景色(例如:字的顏色)

13、QIcon QTableWidgetItem::icon() const

返回項的圖示

14、bool QTableWidgetItem::isSelected() const

返回項是否被選擇

15、void QTableWidgetItem::read(QDataStream & in)

     從流中讀取項???

16、int QTableWidgetItem::row() const

   返回項所在的行,如果沒有在表中,返回-1

17、void QTableWidgetItem::setBackground(constQBrush & brush)

   設定項的背景色

18、void QTableWidgetItem::setCheckState(Qt::CheckState state)

  設定項的被點選狀態。

19、void QTableWidgetItem::setData(int role, constQVariant & value)

     設定給定角色的值。

20、void QTableWidgetItem::setFlags(Qt::ItemFlags flags)

  設定項的標誌:是否被選擇等。

21、void QTableWidgetItem::setFont(constQFont & font)

  設定項的字型

22、void QTableWidgetItem::setForeground(constQBrush & brush)

  設定項的前景色

23、void QTableWidgetItem::setIcon(constQIcon & icon)

設定項的圖示

24、void QTableWidgetItem::setSelected(bool select)

   設定項是否被選擇

25、void QTableWidgetItem::setSizeHint(constQSize & size)

  設定項的提示大小(提示大小有預設大小的意思)

26、void QTableWidgetItem::setStatusTip(constQString & statusTip)

   設定項的狀態提示

27、void QTableWidgetItem::setText(constQString & text)

  設定項顯示的文字

28、void QTableWidgetItem::setTextAlignment(int alignment)

  設定文字對齊方式

The horizontal flags are:

Constant Value Description
Qt::AlignLeft 0x0001 Aligns with the left edge.
Qt::AlignRight 0x0002 Aligns with the right edge.
Qt::AlignHCenter 0x0004 Centers horizontally in the available space.
Qt::AlignJustify 0x0008 Justifies the text in the available space.

The vertical flags are:

Constant Value Description
Qt::AlignTop 0x0020 Aligns with the top.
Qt::AlignBottom 0x0040 Aligns with the bottom.
Qt::AlignVCenter 0x0080 Centers vertically in the available space.

You can use only one of the horizontal flags at a time. There is one two-dimensional flag:

Constant Value Description
Qt::AlignCenter AlignVCenter | AlignHCenter Centers in both dimensions.

29、void QTableWidgetItem::setToolTip(constQString & toolTip)

  設定工具提示(提示這是項是幹什麼用的,與狀態提示有區別)

30、void QTableWidgetItem::setWhatsThis(constQString & whatsThis)

  設定幫助資訊

31、QSize QTableWidgetItem::sizeHint() const

   返回項的提示大小

32、QString QTableWidgetItem::statusTip() const

  返回項的狀態提示

33、QTableWidget * QTableWidgetItem::tableWidget() const

  返回項所在的表

34、QString QTableWidgetItem::text() const

  返回項的顯示的文字

35、int QTableWidgetItem::textAlignment() const

  返回項文字的對齊方式

36、QString QTableWidgetItem::toolTip() const

  返回項的工具提示

37、int QTableWidgetItem::type() const

     返回項的型別

38、QString QTableWidgetItem::whatsThis() const

   返回項的幫助資訊

39、void QTableWidgetItem::write(QDataStream & out) const

    將項寫入流

40、bool QTableWidgetItem::operator<(constQTableWidgetItem & other) const

     項的運算子過載:<

41、QTableWidgetItem & QTableWidgetItem::operator=(constQTableWidgetItem & other)

     項的運算子過載:=