找回密码
 立即注册

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

查看数: 11550 | 评论数: 7 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2018-7-9 13:55

正文摘要:

回复

liuxunwei 发表于 2019-2-1 09:32:44
这个我遇到过,你可以自定义实现QStyledItemDelegate这个委托类,实现其中的paint和sizeHint函数,如果需要事件实现指定事件的话,你可以实现其中的editorEvent虚函数,在paint函数绘制自己所需要的界面

本帖子中包含更多资源

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

x
HangZhouLeo 发表于 2019-1-31 15:44:20
addwidget();这个接口可以传入自定义窗口
ypb_6010 发表于 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.

是不是要这个?
QT_从入门到转行 发表于 2018-7-11 11:20:17
Since 发表于 2018-7-11 09:58
哦,对不起,打扰了,我不知道这个问题,我去文档看了,没看到有自定义 Delegate 的东西,你也可以去百度看 ...

好,,谢谢,,,,,
Since 发表于 2018-7-11 09:58:52
哦,对不起,打扰了,我不知道这个问题,我去文档看了,没看到有自定义 Delegate 的东西,你也可以去百度看看~
QT_从入门到转行 发表于 2018-7-11 09:06:31
Since 发表于 2018-7-9 16:37
QListView  是用来显示 Model 数据的,你把 QWidget 放进去干嘛?

我就是要用QListView来显示自定义窗体 啊,,,,
Since 发表于 2018-7-9 16:37:02
QListView  是用来显示 Model 数据的,你把 QWidget 放进去干嘛?

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