I can't find any way to put a line between items in my list. Am I missing something?
Qt: QListWidget separator line between items?
Asked Answered
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
Ah beautiful. I missed this in the documentation. That's kind of a real nice feature. –
Callable
2 improvements to the accepted answer:
- Use the color palette of the widget to achieve a uniform look across different systems.
- It is necessary to restore the
item:selected
style when restylingitem
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:
© 2022 - 2024 — McMap. All rights reserved.