在QTableWidget中可以添加多種Qt的空間信息,本文只以QPushButton為例進行說明:
// 創建QPushButton控件 QPushButton *pBtn = new QPushButton(); // 綁定信號 connect(pBtn, SIGNAL(clicked()), this, SLOT(OnBtnClicked())); // 在QTableWidget中添加控件 tableWidget->setCellWidget(0,0,pBtn); // 綁定的響應函數 void OnBtnClicked(void) { QPushButton *senderObj=qobject_cast<QPushButton*>(sender()); if(senderObj == nullptr) { return; } QModelIndex idx =tableWidget->indexAt(QPoint(senderObj->frameGeometry().x(),senderObj->frameGeometry().y())); int row=idx.row(); // 其他響應信息...... }
當然,也可以添加其他控件、布局、貼圖等。
