如何在QTableWidget中实现QCheckBox
2012-06-29 18:43
696 查看
以下是我的cpp文件内容:
QTableWidgetItem *asd=new QTableWidgetItem();
asd->setCheckState(Qt::Checked);
ui->tableWidget->setColumnCount(3);
ui->tableWidget->setRowCount(3);
ui->tableWidget->setItem(0,0,asd);
}
Widget::~Widget()
{
delete ui;
}
#include "widget.h" #include "ui_widget.h" #include <QTableWidgetItem> #include <QCheckBox> #include <QHBoxLayout> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); /*这是ui文件中没有放qtablewidget控件时在里面插入QCkeckBox的方法*/ // QTableWidget *table=new QTableWidget(5,5); // QCheckBox *abc=new QCheckBox(""); // table->setCellWidget(0,0,abc); // QHBoxLayout *mainLayout = new QHBoxLayout; // mainLayout->addWidget(table); // setLayout(mainLayout); /*这是ui文件中已经放了QtableWieget控件时在里面插入QCheckBox的方法*/ // QCheckBox *abc=new QCheckBox(""); // ui->tableWidget->setColumnCount(2); // ui->tableWidget->setRowCount(2); // ui->tableWidget ->setCellWidget(0,0,abc); /*这是利用QTableWidget自带的属性插入QCheckBox的方法,据说前两中方法不能读取单选框的选择状态(我测试了一下,发现这种说法并不完全对,尽管失败了)而这种可以读取状态的方法是利用QTableWidget::cellChanged()函数,检查单元格内容的变化,然后连接此信号,在槽函数中检测checkBox的状态。 connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(changeTest(int, int))); void changeTest(int row, int col) { if(tableWidget ->item(row, col)->checkState() == Qt::Checked) //选中 ... else ... } */
QTableWidgetItem *asd=new QTableWidgetItem();
asd->setCheckState(Qt::Checked);
ui->tableWidget->setColumnCount(3);
ui->tableWidget->setRowCount(3);
ui->tableWidget->setItem(0,0,asd);
}
Widget::~Widget()
{
delete ui;
}
相关文章推荐
- 如何在QTableWidget表头(列头)添加QCheckBox控件
- Qt动态布局,多个窗口使用同一个widget如何实现。
- QTableWidget中checkBox如何判断复选框是否被选中
- Qt qtablewidget 实现筛选功能,显示符合条件的整行信息
- Qt如何实现QTableView的撤消与恢复功能
- QTreeView,QTableWidget表头上字,如何左对齐
- QTableView和QTableWidget翻页功能实现
- QTableView和QTableWidget翻页功能实现---Qt学习笔记5
- 关于QTreeWidget显示类似QTableWidget网格的实现
- QTableView和QTableWidget翻页功能实现
- QTableWidget实现鼠标移动整行颜色变化
- QT QTableWidget设置了多行选中后,如何获取所有选中行的索引
- widget的两个快捷方式供选择是如何实现的
- QT QTableWidget中实现整行选中和禁止编辑单元格
- 在Qt5.4中如何实现QOpenGLWidget和QPainter混合编程
- QTableWidget中隔行换色的实现
- 如何实现一个翻页效果的widget
- 如何在Android实现桌面清理内存简单Widget小控件
- QT —— 如何让QTableWidget表格行列填满整个窗口(mainwindow)
- 【转】在 QTableWidget 部件上实现鼠标右键响应功能