使用Qt ItemDelegate [英] Using Qt ItemDelegate

查看:244
本文介绍了使用Qt ItemDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用QStyledItemDelegate为了在我的列表视图中显示路径,以下是我为什么这样做,有路径:

I'm trying to use QStyledItemDelegate in order to display path in my list view, the following is the reason why I'm doing it, having path:

C:\some_path\another_path\and_another_path\and_filnally_some_file.txt  


$ b b

和listView的宽度不足以显示完整路径,我试图修改路径字符串:

and listView which has width which is not wide enough to display full path, I'm trying to modify the path string to:

C:\...\and_another_path\and_filnally_some_file.txt    

这样做将适合视图,但哪个fnc我需要重新实现在我的委托为了实现呢? (我的意思是发送这个修改的字符串到视图)

对字符串的另一个修改我试图做的是加粗文件的名称和灰色的路径的剩余部分,并再次需要在代理中完成,但在哪个函数?油漆?

and by doing so this will fit into view, but which fnc do I need to reimplement in my delegate in order to achieve that? (I'm mean to send this modified string to the view)
Another modification to the string I'm trying to do is to bolden name of the file and grey out rest of the path, and again this needs to be done in delegate but in which function? paint?

推荐答案

QStyledItemDelegate 文档

Subclassing QStyledItemDelegate

如果代理不支持绘制您需要的数据类型或者想要自定义项目的绘图,那么需要对QStyledItemDelegate进行子类化, code> paint()和可能 sizeHint() paint()函数为每个项目单独调用,并且 sizeHint(),可以指定提示

If the delegate does not support painting of the data types you need or you want to customize the drawing of items, you need to subclass QStyledItemDelegate, and reimplement paint() and possibly sizeHint(). The paint() function is called individually for each item, and with sizeHint(), you can specify the hint for each of them.

我建议重新实现两者。

I suggest reimplementing both.

这篇关于使用Qt ItemDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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