Hello Qt -- QT unit assembly

1, QListWidget list cell

1. QListWidget component introduction

QListWidget list unit component inherits from QListView and is a unit based list component. QListWidget can display a list. Each item in the list is an instance of qlistwidgettitem. Each item can be operated through qlistwidgettitem. You can set the image and text of each item through QListWidgetItem.

2. QListWidget component properties

QListWidget list unit component property setting options:

A. Name: the name in the corresponding source code of the component

B. Font: set the font inside the table

C. count: keep the number of items

D. currentRow: keep the row of the current project

E. sortingEnabled: whether to sort item s

3. Common member functions of QListWidget component

QListWidget(QWidget *parent = 0)

Construct a ListWidget whose parent object is parent

void addItem(QListWidgetItem *item)

Add item

void addItem(const QString &label)

Add a new item and add label label to the newly added item

void addItems(const QStringList &labels)

Add a list of items

void clear() [slot]

Clear all items in this ListWidget

QListWidgetItem *currentItem() const

Returns the currently active project

void editItem(QListWidgetItem *item)

If the item is editable, start editing the item

QList<QListWidgetItem *> findItems(const QString &text,Qt: : MatchFlags flags) const

Find the item matching the string text and return the search result

void insertItem(int row,QListWidgetItem * item)

Insert item at row

void insertItem(int row,const QString &label)

This is an overloaded function with the same function as (9). Insert a new item labeled label at row

void insertItem(int row,const QStringList &labels)

Insert a column of items at row

QListWidgetItem * item(int row) const

Returns the item at row. If there is no item at row, 0 is returned

QListWidgetItem * itemAt(const QPoint &p) const

Returns the item at point p

QListWidgetItem * itemAt(int row,int y) const

Returns the item at coordinates (x, y)

QWidget * itemWidget(QListWidgetItem *item) const

Returns the control displayed at the item of the item

QListWidgetItem * takeItem(int row)

Removes the item at row row and returns the item control

void removeItemWidget(QListWidgetItem *item)

Remove control at item

int row(const QListWidgetItem *item) const

Returns the line of the item

QList<QListWidgetItem*> selectedItems() const

Returns the control of all selected items

void setcurrentItem(QListWidgetItem *item)

Set item as current item

void setItemWidget(QListWidgetItem *item,QWidget *widget)

Set the control widget as the display control of the item

void setItemWidget(QListWidgetItem *item,QWidget *widget)

void sortItems(Qt: : SortOrder order = Qt: : AscendingOrder)

Sort items by order

4. QListWidget instance

#include <QtGui/QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QListWidget>
#include <QListWidgetItem>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget* widget = new QWidget;
    QListWidget* listWidget = new QListWidget(widget);
    QVBoxLayout* layout = new QVBoxLayout;
    QListWidgetItem* lst1 = new QListWidgetItem("data", listWidget);
    QListWidgetItem* lst2 = new QListWidgetItem("decision", listWidget);
    QListWidgetItem* lst3 = new QListWidgetItem("document", listWidget);
    QListWidgetItem* lst4 = new QListWidgetItem("process", listWidget);
    QListWidgetItem* lst5 = new QListWidgetItem("printer", listWidget);
    listWidget->insertItem(1, lst1);
    listWidget->insertItem(2, lst2);
    listWidget->insertItem(3, lst3);
    listWidget->insertItem(4, lst4);
    listWidget->insertItem(5, lst5);
    listWidget->show();
    layout->addWidget(listWidget);
    widget->setLayout(layout);

    widget->show();

    return a.exec();
}

2, QTreeWidget tree cell

1. Introduction to QTreeWidget component

QTreeWidget tree cell component inherits from QTreeView class. It is a tree view that uses a predefined model and is also a component based on Model / view structure. In order to facilitate developers to use tree view, it can be used to create a simple tree structure list. The tree structure is realized through QTreeWidget class and qtreewidgettitem class, and qtreewidgettitem class realizes the addition of nodes.

2. QTreeWidget component properties

QTreeWidget component property setting options:

A. Name: the name in the corresponding source code of the component

B. font: set the font inside the table

C. columnCount: the number of columns in which the TreeWidget is saved

3. Common member functions of QTreeWidget component

QTreeWidget(QWidget *parent = 0)

Construct a TreeWidget whose parent object is parent

void addTopLevelItem(QTreeWidgetItem * item)

Add item as the top-level item in the QTreeWidget component

void addTopLevelItems(const QList<QTreeWidgetItem*> &items)

Add the items in items as top-level items to the TreeWidget

void clear() [slot]

Clear all items in TreeWidget

void collapseItem(const QTreeWidgetItem *item) [slot]

Collapse item

int currentColumn() const

Returns the currently active column

QTreeWidgetItem *currentItem() const

Returns the current active item

void editItem(QTreeWidgetItem *item,int column = 0)

If the item of column is editable, start editing

void expandItem(const QTreeWidgetItem *item) [slot]

Expand project

QList<QTreeWidgetItem*> findItems(const QString &text,Qt::MatchFlags flags,
            int column = 0)const

Find the item of text matching the string and return the search result

QTreeWidgetItem *headerItem() const

Return header item

QModelIndex indexFromItem(QTreeWidgetItem *item,int column = 0) const [protected]

Returns the item model index of the column column

int indexOfTopLevelItem(QTreeWidgetItem *item) const

Returns the model index of the top-level item. If the item does not exist, - 1 is returned

int sortColumn() const

Returns the sorted column

void sortItems(int column,Qt::SortOrder order)

Sort the items of column by order

QTreeWidgetItem *itemAbove(const QTreeWidgetItem *item) const

Returns the previous item of item

QTreeWidgetItem *itemAt(const QPoint &p) const

Returns the item at point p

QTreeWidgetItem *itemAt(int x,int y) const

Returns the item at coordinates (x, y)

void setItemWidget(QTreeWidgetItem *item,int column,QWidget *widget)

Set the control widget as the display control of the item, which is in the column

QTreeWidgetItem *itemBelow(const QTreeWidgetItem *item) const

Return the next item of item

QWidget *itemWidget(QTreeWidgetItem *item,int column) const

Returns the item display control in the column column

void removeItemWidget(QTreeWidgetItem *item,int column)

Remove the display control of the item in the column column

QList<QTreeWidgetItem *> selectItems() const

Returns all selected items

void setCurrentItem(QTreeWidgetItem *item)

Set item as current item

void setCurrentItem(QTreeWidgetItem *item,int column)

Set the item of column column as the current item

void setHeaderItem(QTreeWidgetItem *item)

Set item as the header item of the TreeWidget

void setHeaderLabel(const QString &label)

Set label as header title

QTreeWidgetItem * topLevelItem(int index) const

Returns the top-level items of all index es

4. QTreeWidget instance

#include <QtGui/QApplication>
#include <QWidget>
#include <QTreeWidgetItem>
#include <QTreeWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *widget = new QWidget;

    QTreeWidget *tree = new QTreeWidget(widget);
    tree->setColumnCount(1); //Set the number of columns
    tree->setHeaderLabel(QString::fromLocal8Bit("Image selection")); //Set header title
    QTreeWidgetItem *Item1 = new QTreeWidgetItem(tree,QStringList(QString::fromLocal8Bit("Image 1")));
    QTreeWidgetItem *Item11 = new QTreeWidgetItem(Item1,QStringList(QString::fromLocal8Bit("Band1"))); //Child node 1

    Item1->addChild(Item11); //Add child node
    QTreeWidgetItem *Item2 = new QTreeWidgetItem(tree,QStringList(QString::fromLocal8Bit("Image 2")));
    QTreeWidgetItem *Item21 = new QTreeWidgetItem(Item2,QStringList(QString::fromLocal8Bit("Band1"))); //Child node 1
    QTreeWidgetItem *Item22 = new QTreeWidgetItem(Item2,QStringList(QString::fromLocal8Bit("Band2"))); //Child node 2

    Item2->addChild(Item21);  //Add child node
    Item2->addChild(Item22);
    tree->expandAll(); //Expand all nodes
    widget->show();

    return a.exec();
}

3, QTableWidget table cell

1. QTableWidget component introduction

QTableWidget table cell component inherits from QTableView. QTableView can use custom data model to display content, while QTableWidget can only use standard data model, and its cell data is realized by the object of QTableWidget. QTableWidget is used to represent a cell in the table, and the whole table needs to be built cell by cell.

2. QTableWidget component properties

QTableWidget component property setting options:

A. Name: the name in the corresponding source code of the component

B. Font: set the font corresponding to the table

C. columnCount: the number of columns saved

D. rowCount: number of rows saved

3. QTableWidget component common member functions

QTableWidget(QWidget * parent = 0)

Construct a TableWidget whose parent object is parent

QTableWidget(int rows,int columns,QWidget *parent = 0)

Construct a TableWidget control with rows, columns and parent object

QWidget *cellWidget(int row,int column) const

Returns the control at the cell of row and column

void clear() [slot]

Delete all items in this TreeWidget

 void clearContents() [slot]

Delete all items except header in the TreeWidget

int column(const QTableWidgetItem *item) const

Returns the column of the item

int currentColumn() const

Returns the currently active column

QTableWidgetItem * currentItem() const

Returns the currently active project

int currentRow() const

Returns the currently active row

void editItem(QTableWidgetItem *item)

If the item is editable, start editing the item

QList<QTableWidgetItem *> findItems(const QString &text,Qt::MatchFlags flags)const

Finds an item that matches the string text and returns the search result

void insertColumn(int column) [slot]

Insert a new column at column

void insertRow(int row) [slot]

Insert new row at row

QTableWidgetItem *item(int row,int column) const

Returns the item at row, column and column

QTableWidgetItem *itemAt(const QPoint &point) const

Returns the item at point

QTableWidgetItem *itemAt(int ax,int ay) const

Returns the item at the coordinates (ax, ay)

void removeCellWidget(int row,int column)

Remove display controls at row, column, and column cells

void removeColumn(int column)[slot]

Remove column

void removerRow(int row)[slot]

Remove row

int row(const QTableWidgetItem *item) const

Return the line of item

QList<QTableWidgetItem *> selectedItems()

Returns all selected items

void setCellWidget(int row,int column,QWidget *widget)

Set the display control at row and column as widget.

void setCurrentCell(int row,int column)

Set row and column. The cell at column is the current active cell

void setCurrentItem(QTableWidgetItem *item)

Set item as the current active item

void setHorizontalHeaderItem(int column,QTableWidgetItem *item)

Set the item item as the horizontal header item of the column. The function is the same as setVerticalHeaderItem()

void setHorizontalHeaderLabels(const QStringList *labels)

Set the horizontal title as labels, and the function is the same as setVerticalHeaderLabels()

void setItem(int row,int column,QTableWidgetItem *item)

Set the items of row and column cells to item

void sortItems(int column,Qt::SortOrder order = Qt::AscendingOrder)

Sort the column s by order

QTableWidgetItem *takeHorizonalHeaderItem(int column)

Remove the horizontal header item of column. The function is the same as takeVerticalHeaderItem()

QTableWidgetItem *takeItem(int row,int column)

Remove items at row, column, and column cells

QTableWidgetItem *verticalHeaderItem(int row) const

Returns the vertical header item of row row

4. QTableWidget instance

#include <QtGui/QApplication>
#include <QTableWidget>
#include <QTableWidgetItem>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QTableWidget *tablewidget = new QTableWidget(10,5);
    tablewidget->resize(350, 200);  //Set table
    QStringList header;
    header<<"Month"<<"Description";
    tablewidget->setHorizontalHeaderLabels(header);
    tablewidget->setItem(0,0,new QTableWidgetItem("Jan"));
    tablewidget->setItem(1,0,new QTableWidgetItem("Feb"));
    tablewidget->setItem(2,0,new QTableWidgetItem("Mar"));
    tablewidget->setItem(0,1,new QTableWidgetItem("Jan's month"));
    tablewidget->setItem(1,1,new QTableWidgetItem("Feb's month"));
    tablewidget->setItem(2,1,new QTableWidgetItem("Mar's month"));
    tablewidget->show();

    return a.exec();
}

Keywords: Qt

Added by gfX on Thu, 03 Mar 2022 22:14:33 +0200