3

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?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
hokkos
  • 500
  • 6
  • 17

3 Answers3

5

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;
}
quornian
  • 9,495
  • 6
  • 30
  • 27
  • You are correct, because both are subclasses of QAbstractItemView. But the support is not good and your second example does not work for instance. The first one does, however (for a QListView). – user362515 Mar 04 '15 at 07:56
0
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

Barbaris
  • 1,256
  • 7
  • 7
  • Well, if you want to do that *only* using QSS, it seems it is not going to happen, however if you really want to to that, use QStylePainter and implement your own widget that would take QComboBox elements such as QStyle::SE_CheckBoxIndicator to place it wherever you want and render natively for your target platform. – Barbaris Apr 12 '11 at 14:46
0

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

hokkos
  • 500
  • 6
  • 17