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

qt中如何在QListView中添加自定义的QWidget

7
回复
11530
查看
[复制链接]
累计签到:14 天
连续签到:1 天
来源: 2018-7-9 13:55:26 显示全部楼层 |阅读模式
1Qter豆

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

使用道具 举报

累计签到:1 天
连续签到:1 天
2019-2-1 09:32:44 显示全部楼层
这个我遇到过,你可以自定义实现QStyledItemDelegate这个委托类,实现其中的paint和sizeHint函数,如果需要事件实现指定事件的话,你可以实现其中的editorEvent虚函数,在paint函数绘制自己所需要的界面

本帖子中包含更多资源

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

x
回复

使用道具 举报

累计签到:11 天
连续签到:3 天
2019-1-31 15:44:20 显示全部楼层
addwidget();这个接口可以传入自定义窗口
回复

使用道具 举报

累计签到:45 天
连续签到:1 天
2018-9-29 18:04:19 显示全部楼层
void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget)
Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.
If index is invalid (e.g., if you pass the root index), this function will do nothing.
The given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the item at the given index.
If index widget A is replaced with index widget B, index widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.

  setIndexWidget(index, new QLineEdit);
  ...
  setIndexWidget(index, new QTextEdit);

This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.
This function was introduced in Qt 4.1.

是不是要这个?
回复

使用道具 举报

累计签到:14 天
连续签到:1 天
2018-7-11 11:20:17 显示全部楼层
Since 发表于 2018-7-11 09:58
哦,对不起,打扰了,我不知道这个问题,我去文档看了,没看到有自定义 Delegate 的东西,你也可以去百度看 ...

好,,谢谢,,,,,
回复

使用道具 举报

累计签到:742 天
连续签到:1 天
2018-7-11 09:58:52 显示全部楼层
哦,对不起,打扰了,我不知道这个问题,我去文档看了,没看到有自定义 Delegate 的东西,你也可以去百度看看~
回复

使用道具 举报

累计签到:14 天
连续签到:1 天
2018-7-11 09:06:31 显示全部楼层
Since 发表于 2018-7-9 16:37
QListView  是用来显示 Model 数据的,你把 QWidget 放进去干嘛?

我就是要用QListView来显示自定义窗体 啊,,,,
回复

使用道具 举报

累计签到:742 天
连续签到:1 天
2018-7-9 16:37:02 显示全部楼层
QListView  是用来显示 Model 数据的,你把 QWidget 放进去干嘛?
回复

使用道具 举报

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

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