'How to increase the padding (or margins) for an item/row in a QListWidget?
We're looking for a way to increase the padding (or margins) for a QListWidget we are using in our application. We'd like to increase this for all four directions to give the text in our list some extra space
I've looked at the documentation for both QListWidget and QListWidgetItem and can't find anything. For QListWidget there's setContentsMargins which is inherited from QWidget but that is for the widget as a whole (rather than individual entries).
What can we do to solve this? Grateful for help!
Solution 1:[1]
how about this
ui->listWidget->setStyleSheet("QListWidget {padding: 10px;} QListWidget::item { margin: 10px; }");
Solution 2:[2]
we use css selector for thise
list = QListWidget()
list.addItem("item 1")
list.addItem("item 2")
list.addItem("item 3")
list.setStyleSheet("""
QListWidget {
background-color: red;
padding:20px;
}
QListWidget::item {
margin:20px;
background-color: blue;
}
""")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | eyllanesc |
| Solution 2 | Roshan Yadav |
