如何在 QListView 中设置复选框的样式以使标签位于复选框下方?
我有一个水平的 QListView,我想使用样式表自定义其中的复选框和标签,以将标签放在复选框下方,而不是右侧。
怎么办呢?
I have an horizontal QListView
and I want to customize the checkbox and label inside with a stylesheet to put the label under the checkbox, not at the right side.
How can it be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否适用于您的情况,但我正在寻找类似的东西(对于
QTreeWidget
复选框)并发现这有效:我想
QListView
会还有一个指标
,但我现在无法测试。试试这个:I'm not sure if this will work in your case but I came looking for a similar thing (for
QTreeWidget
checkboxes) and found that this works:I imagine the
QListView
would also have anindicator
, but I can't test right now. Try this:会做这项工作。该解决方案很丑陋但有效。不确定它是否始终有效 - 您可能需要使用 QCheckBox 的布局策略或查看是否可以为其预先分配足够的空间。再说一遍——没有承诺。它适用于我的 Qt 4.7.1 测试示例
will do the job. The solution is ugly but works. Not sure that it will work always - you may need to play with layout policies of QCheckBox or see whether you can preallocate enough space for it. Again - no promises. It worked on my test example with Qt 4.7.1
因此,唯一的解决方案是使用自定义复选框和标签创建一个样式项目委托,只需调整以下代码:
http://discussion.forum.nokia.com/forum/showthread.php?217027-Display-widget-as-items-in-a-QListView&p=813138&viewfull=1#post813138
So the only solution is to create a styled item delegate with your custom checkbox and label, just adapt this code :
http://discussion.forum.nokia.com/forum/showthread.php?217027-Display-widget-as-items-in-a-QListView&p=813138&viewfull=1#post813138