标签:png sign cal oid div 运行程序 sig items tco
一、 .cpp文件
#include "qtablewidgetsort.h" #include <QDebug> QTableWidgetSort::QTableWidgetSort(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); ui.tableWidget->setRowCount(10); ui.tableWidget->setColumnCount(5); QStringList hListheader; hListheader << QString::fromLocal8Bit("姓名"); ui.tableWidget->setHorizontalHeaderLabels(hListheader); ui.tableWidget->setItem(0, 0, new QTableWidgetItem("a")); ui.tableWidget->setItem(1, 0, new QTableWidgetItem("d")); ui.tableWidget->setItem(2, 0, new QTableWidgetItem("c")); ui.tableWidget->setItem(3, 0, new QTableWidgetItem("b")); ui.tableWidget->setItem(4, 0, new QTableWidgetItem("19")); ui.tableWidget->setItem(5, 0, new QTableWidgetItem("15")); ui.tableWidget->setItem(6, 0, new QTableWidgetItem("11")); ui.tableWidget->setItem(7, 0, new QTableWidgetItem(QString::fromLocal8Bit("张三"))); ui.tableWidget->setItem(8, 0, new QTableWidgetItem("qqq")); ui.tableWidget->setItem(9, 0, new QTableWidgetItem("zzzz")); //连接水平表头响应 connect(ui.tableWidget->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sort(int))); } QTableWidgetSort::~QTableWidgetSort() { } void QTableWidgetSort::sort(int col) { ui.tableWidget->sortItems(col, Qt::AscendingOrder); }
二、.h文件
#ifndef QTABLEWIDGETSORT_H #define QTABLEWIDGETSORT_H #include <QtWidgets/QMainWindow> #include "ui_qtablewidgetsort.h" class QTableWidgetSort : public QMainWindow { Q_OBJECT public: QTableWidgetSort(QWidget *parent = 0); ~QTableWidgetSort(); public slots: void sort(int col); private: Ui::QTableWidgetSortClass ui; }; #endif // QTABLEWIDGETSORT_H
三、运行程序
四、效果图
标签:png sign cal oid div 运行程序 sig items tco
原文地址:https://www.cnblogs.com/jiangson/p/9147662.html