[Qt-interest] Qt-interest Digest, Vol 19, Issue 229
jiangzhw2008
jiangzhw2008 at yeah.net
Wed Jun 30 14:17:37 CEST 2010
"how to set check box on QTableWidget's header (jiangzhw2008)" solved as follows:
1.refer to
http://developer.qt.nokia.com/faq/answer/how_can_i_insert_a_checkbox_into_the_header_of_my_view
and i change the
option.rect = QRect(10,10,10,10)
to
option.rect = QRect(0,0,25,25)
so as to make the checkbox be normal.
add emit headerDataChanged(isOn)
in the function mousepressevent();
2. add following code in OrgDevDtlMW.cpp where i init the QTableWidget:
TableChkBoxHeader *chkHeader=new TableChkBoxHeader(Qt::Horizontal,ui->tableWidget);
ui->tableWidget->setHorizontalHeader(chkHeader);
QTableWidgetItem* chkAllItem = new QTableWidgetItem(tr("全选"));
chkAllItem->setCheckState(Qt::Unchecked);
ui->tableWidget->setHorizontalHeaderItem(0, chkAllItem);
connect(chkHeader,SIGNAL(headerDataChanged(bool)),this,SLOT(updateSonChkState(bool)));
and the slot function is as follows:
void OrgDevDtlMW::updateSonChkState(bool checkState){
qDebug()<<"begin updateSonChkState";
for(int i=0;i<ui->tableWidget->rowCount();i++){
if(checkState){
ui->tableWidget->item(i,0)->setCheckState(Qt::Checked);
}else{
ui->tableWidget->item(i,0)->setCheckState(Qt::Unchecked);
}
}
qDebug()<<"end updateSonChkState";
}
Zhengwei JIANG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100630/7e7890cd/attachment.html
More information about the Qt-interest-old
mailing list