Table Widget API
For the objects provided by tables and cells in Qt, CukeTest provides two controls, Table
and TableItem
. And it provides APIs for manipulating table data around table-related controls, which can be satisfied whether it is obtaining or editing. The type files are as follows:
Corresponding exercises are also provided for the table controls-[Exercise: Operating Table in Qt Applications] (../walk/qt_table_linux.md), which can greatly deepen the understanding of the API.## Table control: Table {#table-contron}
Used to describe the object type of the table view control-Table
, because it is a view component of Qt, it can change the display effect such as sorting, and it exists as a composite container of cells.
Type Definition
export interface IQTable extends IQtControl {
getItem(rowIndex: number, columnInndex: number): IQTableItem;
findItem(text: string): Promise<IQTableItem | null>;
scrollTo(rowIndex: number, columnIndex:number): Promise<void>;
scrollToBottom(): Promise<void>;
cellValue(rowIndex: number, columnNameOrIndex: number | String): Promise<string>;
setCellValue(rowIndex: number, columnNameOrIndex: number | String, value: String): Promise<void>;
columnHeaders(): Promise<string[]>;
data(): Promise<string[][]>;
rowData(rowIndex: number): Promise<string[]>
rowCount(): Promise<number>;
columnCount(): Promise<number>;
}
getItem(rowIndex, colIndex): TableItem
Get the cell object at the specified row and column position.
- rowIndex:
number
type, representing the row position index of the target cell, starting from 0 to calculate the position; - colIndex:
number
type, representing the column position index of the target cell, starting from 0 to calculate the position; - Return value:
TableItem
type, which is the automation object of the target cell control type. If the cell corresponding to the row and column position is invalid, the error of1003: ObjectNotExist
will appear after the call.
findItem(text: string): Promise<IQTableItem | null>
Search for the target cell based on the name, and return the automation object of the target cell, or return null
if it is not found.
- text:
string
type, the content or text of the desired target cell; - Return value:
Promise<IQTableItem>
orPromise<null>
type, asynchronously search the target cell in the application, and returnnull
if it is not found.
scrollTo(rowIndex, colIndex): Promise<void>
Scroll to the target index position. If the target location has not been loaded, it will be loaded until the target index location is loaded.
- rowIndex:
number
type, representing the row position index of the target cell, starting from 0 to calculate the position; - colIndex:
number
type, representing the column position index of the target cell, starting from 0 to calculate the position; - Return value: Asynchronous method that does not return any value.
scrollToBottom(): Promise<void>
Scroll to the bottom of the table.
- Return value: Asynchronous method that does not return any value.
setCellValue(rowIndex, columnNameOrIndex, value): Promise<void>
Edit the value of the target row and column cell, the column position can also be passed in a string, if you do so, it will look for the corresponding column position in the header.
- rowIndex:
number
type, representing the row position index of the target cell, starting from 0 to calculate the position; - colNameOrIndex:
number
type orstring
type, representing the column position index of the target cell, starting from 0 to calculate the position; you can also pass in the name of the target column in the header, such as "Name", ' ID" or something. - value:
string
type, the expected cell value. - Return value: Asynchronous method that does not return any value. If the row and column position exceeds, or the column name passed in does not exist,
1006: OutOfRange
will be thrown.
cellValue(rowIndex, columnNameOrIndex): Promise<string>
Get the value of the target row and column cell, which can be understood as the Getter
method relative to the setCellValue()
method.
- rowIndex:
number
type, representing the row position index of the target cell, starting from 0 to calculate the position; - colNameOrIndex:
number
type orstring
type, representing the column position index of the target cell, starting from 0 to calculate the position; you can also pass in the name of the target column in the header, such as "Name", ' ID" or something. - Return value:
Promise<string>
type, return the result ofstring
type asynchronously, no matter what content is in the target cell. If the row and column position exceeds, or the column name passed in does not exist,1006: OutOfRange
will be thrown.
columnHeaders(): Promise<string[]>
Get the content of the header and return it as a string array.
- Return value:
Promise<string[]>
type, asynchronously returns an array ofstring
type, no matter what is in the header.
data(): Promise<string[][]>
Get all the content in the table and return it as a two-dimensional array.
- Return value:
Promise<string[][]>
type, which is a two-dimensional string array.
If the table data is as follows:
Student ID | Name | Gender |
---|---|---|
0001 | Xiao Wang | Male |
0002 | Xiao Ming | Male |
0003 | Little Red | Female |
Then the array returned by the data()
method is as follows:
[
['0001','Xiao Wang','Male'],
['0002','Xiao Ming','Male'],
['0003','Little Red','Female']
]
rowData(rowIndex): Promise<string[]>
Get the data of the target row and return it as a string array.
- rowIndex:
number
type, representing the row position index of the target cell, starting from 0 to calculate the position; - Return value:
Promise<string[]>
type, asynchronously returns an array ofstring
type, no matter what is in the target cell. If the row and column position exceeds, or the column name passed in does not exist,1006: OutOfRange
will be thrown.
rowCount(): Promise<number>
Get the number of rows in the table. If the table contains parts that have not been loaded, only the number of rows that have been loaded will be counted.
- Return value:
Promise<number>
, return the result ofnumber
type asynchronously.
columnCount(): Promise<number>
Get the number of columns in the table. The value is consistent with the length of the array returned by the columnHeaders()
method.
- Return value:
Promise<number>
, return the result ofnumber
type asynchronously.
Cell Control: TableItem
Definition and method for cell control.
Type file definition
export interface IQTableItem extends IQtControl {
select(): Promise<void>;
scrollIntoView(): Promise<void>;
set(value: String): Promise<void>;
value(): Promise<string>;
rowIndex(): Promise<number>;
columnIndex(): Promise<number>;
}
Object manipulation API
The following are the object methods of the TableItem
control.
select(): Promise<void>
Select the target cell.
- Return value: Asynchronous method that does not return any value.
scrollIntoView(): Promise<void>
Scroll to the target cell position.
- Return value: Asynchronous method that does not return any value.
set(value): Promise<void>
Modify the value of the cell directly.
- value:
string
type, the expected cell value. - Return value: Asynchronous method that does not return any value.
value(): Promise<string>
Modify the value of the cell directly.
- Return value:
string
type, the value in the target cell.
rowIndex(): Promise<number>
Get the row index position of the current cell.
- Return value:
number
type, the row index position in the cell.
columnIndex(): Promise<number>
Get the row index position of the current cell.
- Return value:
number
type, the column index position in the cell.
Chinese version click here.