Qt: QListWidget separator line between items?
Asked Answered
C

2

4

I can't find any way to put a line between items in my list. Am I missing something?

Callable answered 15/10, 2011 at 20:24 Comment(0)
P
14

A style sheet would be easiest, for example:

myListWidget->setStyleSheet( "QListWidget::item { border-bottom: 1px solid black; }" );

You'll want to look at some of the style sheet documentation

Pediatrician answered 16/10, 2011 at 0:30 Comment(1)
Ah beautiful. I missed this in the documentation. That's kind of a real nice feature.Callable
U
2

2 improvements to the accepted answer:

  1. Use the color palette of the widget to achieve a uniform look across different systems.
  2. It is necessary to restore the item:selected style when restyling item

E.g. like this:

const auto & palette = tableWidget.palette();
tableWidget.setStyleSheet(QString("QListWidget::item { border-bottom: 1px solid %1; } QListWidget::item:selected { background-color: %2; color: %3; }")
    .arg(palette.midlight().color().name(),
         palette.highlight().color().name(),
         palette.highlightedText().color().name()));

Here you can see that the separator lines and selection color fit the default style of the widget:

enter image description here

Undercoating answered 27/6, 2020 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.