Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: QListWidget separator line after particuler items?

Tags:

qt

qlistwidget

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.

like image 518
Maverick33 Avatar asked Jul 10 '14 08:07

Maverick33


1 Answers

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)

like image 139
Googie Avatar answered Sep 19 '22 19:09

Googie