qStyledItemdelegate / qabtractitemdelegate for Qlistview
我的目的是创建Contact App之类的内容,我可以在其中列出联系人并选择它以查看有关人的信息。我发现可能的解决方案之一是使用QListView + QStyleDitemdelegate / Qabstractitemdelegate。关于它的信息非常困难,因此我不清楚它。
(联系应看起来像)
https://www.sketchappsources.com/free-source/4395-ios-contacts-screen-app-sketch-freebie-resource-resource.html )?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您从数据模型开始。
qstandardItemModel
类,用于开始并使用qstandardItem
类实例填充它。它允许您为项目设置图标,文本,字体,背景,大小和其他属性。请参阅 https://doc.qt.io/qt-5/qt-5/qtand-5/qstand-candardemmodel。 html#详细信息qlistView
使用setModel
qlistView
's单击
代码>信号。要以更复杂的方式渲染项目,您应该
qStyledIteMdelegate
类,它是paint
和sizehint
方法。在Paint
方法中,您应该实现渲染,并且您的sizeHint
方法应返回项目的有效尺寸。请参阅 https://doc.qt.io/qt.io/qt-5/qt-5/qabstractitemdelemdelemdelegate。 html#详细信息data
qmodelindex的方法> qmodelindex
参考将传递给paint
方法。使用不同的角色获取适当的数据。请参阅QListView
bysetItemdelegate
,请使用您的委托类。应将模型设置为QListView,并且以相同方式处理项目点击。
I suggest you to start with a data model.
QStandardItemModel
class for beginning and populate it withQStandardItem
class instances. It would allow you to set icon, text, font, background, size and other properties for items. Refer to https://doc.qt.io/qt-5/qstandarditemmodel.html#detailsQListView
usingsetModel
QListView
'sclicked
signal.To render items in more complex way you should
QStyledItemDelegate
class and it'spaint
andsizeHint
methods. In thepaint
method you should implement rendering and yoursizeHint
method should return a valid size for items. Refer to https://doc.qt.io/qt-5/qabstractitemdelegate.html#detailsdata
method ofQModelIndex
reference that is passed topaint
method. Use different roles to get appropriate data. Refer to https://doc.qt.io/qt-5/qt.html#ItemDataRole-enumQListView
bysetItemDelegate
.Model should be set to QListView and item clicks are handled in same way.