找回密码
 立即注册
收起左侧

如何在tableWidget中的一个单元格设置下拉多选复选框

6
回复
14233
查看
[复制链接]
累计签到:5 天
连续签到:1 天
来源: 2016-12-6 21:40:50 显示全部楼层 |阅读模式
5Qter豆
如题,想要在tableWidget中的一个单元格中实现下拉多选框,

回复

使用道具 举报

累计签到:955 天
连续签到:1 天
2016-12-7 08:35:06 显示全部楼层
void QTableWidget::setCellWidget(int row, int column, QWidget * widget)
Sets the given widget to be displayed in the cell in the given row and column, passing the ownership of the widget to the table.

If cell widget A is replaced with cell widget B, cell widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.

setCellWidget(index, new QLineEdit);
...
setCellWidget(index, new QTextEdit);
回复

使用道具 举报

累计签到:955 天
连续签到:1 天
2016-12-7 08:36:37 显示全部楼层
多看帮助文档会帮助你快速掌握qt常用功能
回复

使用道具 举报

累计签到:597 天
连续签到:1 天
2016-12-7 11:23:35 显示全部楼层
按楼上的方法,我来补充一下:

Qt Designer下添加的tableWidget:



.cpp添加如下代码:
  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent),
  3.     ui(new Ui::MainWindow)
  4. {
  5.     ui->setupUi(this);

  6.     // 添加下拉项的内容
  7.     QStringList m_strList;
  8.     m_strList << "First" << "Second" << "Third";

  9.     // 添加下拉控件
  10.     QComboBox *m_comboBox = new QComboBox();
  11.     m_comboBox->addItems(m_strList);

  12.     // 下拉控件放到tableWidget
  13.     ui->tableWidget->setCellWidget(0, 1, m_comboBox);
  14. }
复制代码
最终效果:




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

累计签到:5 天
连续签到:1 天
2016-12-8 16:36:43 显示全部楼层
shasidaran 发表于 2016-12-7 11:23
按楼上的方法,我来补充一下:

Qt Designer下添加的tableWidget:

恩。我知道这种,但是目前想达到这样的效果。

这只是一级复选框能够三态,二级复选框两态

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

累计签到:5 天
连续签到:1 天
2016-12-8 16:37:42 显示全部楼层
wdmxtk002 发表于 2016-12-7 08:35
void QTableWidget::setCellWidget(int row, int column, QWidget * widget)
Sets the given widget to be  ...

这种方法不能实现多级树形,且进行多选
回复

使用道具 举报

累计签到:597 天
连续签到:1 天
2016-12-8 17:47:57 显示全部楼层

这个不知道能不能有所帮助
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了