QTableWidget执行setCellWidget后,引入的排序问题?
如果表格项是下面的这种普通的子项填入方式,那么,其排序是没有问题的。
如果,每个子项成了QLabel,且以setCellWidget方式填入。那么,排序出现失效问题。
这当如何解决呢?
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , m_pTable1(NULL){ m_pTable1 = new QTableWidget(this); m_pTable1->setGeometry(10, 50, 800, 200); m_pTable1->setRowCount(3); m_pTable1->setColumnCount(3); QTableWidgetItem *pTableWidgetHeader0 = new QTableWidgetItem("name"); QTableWidgetItem *pTableWidgetItem00 = new QTableWidgetItem("chenxueli"); QTableWidgetItem *pTableWidgetItem10 = new QTableWidgetItem("chenqiuyue"); QTableWidgetItem *pTableWidgetItem20 = new QTableWidgetItem("cundaofan"); m_pTable1->setHorizontalHeaderItem(0, pTableWidgetHeader0); m_pTable1->setItem(0, 0, pTableWidgetItem00); m_pTable1->setItem(1, 0, pTableWidgetItem10); m_pTable1->setItem(2, 0, pTableWidgetItem20); QTableWidgetItem *pTableWidgetHeader1 = new QTableWidgetItem("content"); QTableWidgetItem *pTableWidgetItem01 = new QTableWidgetItem("Hello!"); QTableWidgetItem *pTableWidgetItem11 = new QTableWidgetItem("How are you?"); QTableWidgetItem *pTableWidgetItem21 = new QTableWidgetItem("Welcome"); m_pTable1->setHorizontalHeaderItem(1, pTableWidgetHeader1); m_pTable1->setItem(0, 1, pTableWidgetItem01); m_pTable1->setItem(1, 1, pTableWidgetItem11); m_pTable1->setItem(2, 1, pTableWidgetItem21); QTableWidgetItem *pTableWidgetHeader2 = new QTableWidgetItem("status"); QTableWidgetItem *pTableWidgetItem02 = new QTableWidgetItem("success"); QTableWidgetItem *pTableWidgetItem12 = new QTableWidgetItem("success"); QTableWidgetItem *pTableWidgetItem22 = new QTableWidgetItem("fail"); m_pTable1->setHorizontalHeaderItem(2, pTableWidgetHeader2); m_pTable1->setItem(0, 2, pTableWidgetItem02); m_pTable1->setItem(1, 2, pTableWidgetItem12); m_pTable1->setItem(2, 2, pTableWidgetItem22); m_pTable1->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignLeft); m_pTable1->horizontalHeaderItem(1)->setTextAlignment(Qt::AlignHCenter); m_pTable1->horizontalHeaderItem(2)->setTextAlignment(Qt::AlignRight); m_pTable1->setSortingEnabled(true); m_pTable1->setWordWrap(true); resize(900, 300);}