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

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top