How to Use QTableWidget

From Qt Wiki
Revision as of 15:52, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

English Български

How to Use QTableWidget

QTableWidget Overview

Using QTableWidget [qt.io] developers can embed tables inside Qt applications. QTableWidget inherits QTableView [qt.io]. Items in a QTableWidget instance are provided by class QTableWidgetItem [qt.io].

Basic Usage

Set number of rows and columns

Insert labels into the horizontal header

Insert data

The simplest way to insert text into a cell:

Hide vertical header aka the line counter

Hide grid

Set background of the selected items

Disable editing

Selection mode and behavior

The behavior of the table for selecting rows and cells can be customized using methods setSelectionBehavior [qt.io] and setSelectionMode [qt.io]. The following example allows only single selection of a row:

Handling signals

QTableWidget provides appropriate signals for each event such as change of selection, click, double click, etc. [doc.qt.nokia.com] Example of handling double click of a cell:

Example

The following code snippet uses QTableWidget and all described cases above. It has been tested on Symbian^3 device.

  • mainwindow.h
  • mainwindow.cpp

See Also

How to use QTableWidget in Qt [developer.nokia.com]
Customizing QTableView [doc.qt.nokia.com]

Categories: