This is related to Qt: QListWidget separator line between items? But this above answer adds separator line after each items, I would like to know a way to add the separator line after particular items.
Create a QListWidgetItem
representing the separator. Such item would need to have defined the setSizeHint()
, so its height is small, and also the setFlags()
should define Qt::NoItemFlags
, so the item is not selectable, etc. Then, after adding the item to the QListWidget
, place a QFrame
, with its shape set to QFrame::HLine
, as the item's widget (using QListWidget::setItemWidget()
).
As for your additional question from the comment, which is:
I want to add some gap on each sides of this separator line/frame. How can I achieve this?
The only solution that comes to my mind right now is to embed the QFrame
inside of another QWidget
and put the QWidget
as item's widget (remember that you need to add a layout manager to the QWidget
in order to embed anything in it). Then set proper margins on the widget: QWidget::setContentsMargins(int left, int top, int right, int bottom)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With