How to style the checkbox in a QListView so that the label is under the checkbox?
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?
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:
tree_widget.setStyleSheet("QTreeView::indicator:checked { background:red; }");
I imagine the QListView
would also have an indicator
, but I can't test right now. Try this:
QListView::indicator {
subcontrol-position: top center;
}
QCheckBox::indicator {
subcontrol-position: top center;
}
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
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
精彩评论