将删除按钮添加到QListView中的每个项目 [英] Add a delete Button to each Item in QListView

查看:901
本文介绍了将删除按钮添加到QListView中的每个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以某种方式向QListview中的每个项目添加一个删除对象onClick的按钮?如下图所示:

Is it somehow possible to add to each Item in a QListview a Button which is deleting the Object onClick? As shown in the following Picture:

由于我是QT新手,所以有一些示例会更好,以便更好地理解它.似乎有三种不同的方式?最好的是什么?是否使用QAbstractItemView?

As I'm new in QT it would be nice to have some example, to understand it better. And as it seems there are three different Ways? What will be the best? Do use a QAbstractItemView?

推荐答案

是.您需要使用:

QAbstractItemView::setIndexWidget ( const QModelIndex & index, QWidget * widget )

QListView继承了QAbstractItemView,并且当您尝试自定义列表/树视图时,通常这是查看的地方.但是要小心,没有代表,这将无法很好地扩展.看看这个线程: http://www.qtcentre.org/线程/26916-insertting-custom-Widget-to-listview

QListView inherits QAbstractItemView and when you're trying to customize list/tree views that's usually the place to look. Be careful though, without a delegate this doesn't scale very well. Check out this thread: http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview

这篇关于将删除按钮添加到QListView中的每个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆