【Qt】在QTableWidget中添加QCheckBox并使其居中显示【2012-11-21更新】
2012-11-21 16:41
387 查看
实现思路:把QCheckBox嵌入式到一个水平布局中
获取CheckBox的指针的方法
备注:
可使用 qDebug() << widget->children(); 输出widget的child列表
从而判断CheckBox的index
QWidget *widget; QHBoxLayout *hLayout; QCheckBox *ckb; ... ckb = new QCheckBox(); hLayout = new QHBoxLayout(); widget = new QWidget(ui->tableWidget); hLayout->addWidget(ckb); hLayout->setMargin(0); // 必须添加, 否则CheckBox不能正常显示 hLayout->setAlignment(ckb, Qt::AlignCenter); widget->setLayout(hLayout); ... ui->tableWidget->setCellWidget(row, column, widget);
获取CheckBox的指针的方法
QWidget *widget = (QWidget *)ui->tableWidget->cellWidget(row, column); QCheckBox *ckb = (QCheckBox *)widget->children().at(1); ckb->setChecked(true); ...
备注:
可使用 qDebug() << widget->children(); 输出widget的child列表
从而判断CheckBox的index
相关文章推荐
- [Qt] 在QTableWidget中添加QCheckBox并使其居中显示 [2012-11-21更新]
- 在QTableWidget中添加QCheckBox并使其居中显示(转)
- 在QTableWidget中添加QCheckBox并使其居中显示(转)
- [Qt] 在QTableWidget中添加右键菜单 [2013-06-17更新]
- Qt自适应大小显示图片,添加菜单
- Qt 5.0 for mac 添加程序可执行文件图标 和 dock窗口显示图标
- Qt:添加点击事件的Label并显示图片
- Qt 让弹出的窗口居中显示
- 【Qt】窗口居中显示
- HTML5 - div 添加图片显示居中
- IIS 添加网站显示错误消息 “无更多可用的内存以更新安全信息” 解决方法
- Qt窗口屏幕设置大小与居中显示
- 在更新数据库时VS的ADO.NET 实体数据模型中正确显示新添加的实体
- DataGrid添加小图标,单击居中显示图片(有点差异,第2次才能把图片正确得显示)
- QTableWidget设置网格线粗细 单元格中添加控件并居中
- div中添加背景图片及居中显示
- 嗷,库存管理系统内侧版!!!(添加所有数据验证,修改模块显示方式,更新所有图标)
- Qt 关于弹出对话框,实现居中显示!
- (转载)QT主窗体在屏幕居中显示
- QT Model/View框架中更新Model时View的显示问题