Pregunta

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

¿Fue útil?

Solución

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top