Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create grid style QListWidget?

I'm currently working on a list which I'd like to have set up in a grid style and was curious how I could go about that. I don't believe a table will work because I'd like to have it formatted like this:

option  option  option  option

option  option  option  option

option  option  option  option

option  option  option  option

~4 options per row and no further information split into columns where each row represents a single ListWidgetItem.

like image 542
Obj3ctiv3_C_88 Avatar asked Oct 14 '25 08:10

Obj3ctiv3_C_88


1 Answers

You're looking for something like this (explanation is inline):

QListWidget *listWidget = new QListWidget;

//Dynamically adjust contents to viewport size.
listWidget->setResizeMode(QListView::Adjust);

//Forces the layout into a grid (64x64 is an arbitrary value).
listWidget->setGridSize(QSize(64, 64));

//As an alternative to using setGridSize(), set a fixed spacing between items in the layout:
listWidget->setSpacing(someInt);

//This sets the Flow to LeftToRight, which is more natural in a grid.
listWidget->setFlow(QListView::LeftToRight);

Play with these properties in Qt Designer. Start by setting QListView::Flow and going from there until you get the behavior you desire.

like image 101
jonspaceharper Avatar answered Oct 16 '25 21:10

jonspaceharper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!