PDA

View Full Version : Adding List of Images with filenames and a combobox for each



sRB
30th January 2015, 06:17
Hi All,

I need to display a list of images . This list contains images along with the image name specified below it along with a combobox.
What is the best solution? Do i use a grid layout to place the items one below the other or use a QListWidget instead.
I hope someone could help me with this.
Thanks in advance!

ChrisW67
1st February 2015, 05:55
How many images? Is the number variable or fixed?

For a small number a vertical layout containing a custom widget per image, perhaps in a scroll area, might be appropriate.
For a large or variable list of images a list widget with a customised delegate might be better suited.

sRB
2nd February 2015, 06:13
I have a 100 images and the number is fixed.
How do i go about creating a customised delegate?

Added after 1 18 minutes:

Currently i have created a Listwidgetand added the items to the list using a for loop. The list widget is then added to vBoxLayout. But the list appears as a small box on the top left corner of the window. How do i make the contents fit to screen.

anda_skoa
2nd February 2015, 09:42
I
Currently i have created a Listwidgetand added the items to the list using a for loop. The list widget is then added to vBoxLayout. But the list appears as a small box on the top left corner of the window. How do i make the contents fit to screen.
That either means that the widget is not in a layout or that they layout is not set on the parent widget (or not added to a parent layout).

Cheers,
_

sRB
2nd February 2015, 11:44
I'm adding the list widget to the group box and then setting a scrollwidget for it and adding that to the layout. But still the problem persists.

Here's my code:



QVBoxLayout *vLayout = new QVBoxLayout(parent);
QGroupBox *groupBox = new QGroupBox();
QListWidget *list = new QListWidget();


for()
{
list->setViewMode(QListView::ListMode);
list->setIconSize(QSize(500,500));
list->setResizeMode(QListView::Adjust);
list->addItem(new QListWidgetItem(QIcon(filename),filename));
}


vLayout->addWidget(list);

groupBox->setLayout(vLayout);
scrollArea = new QScrollArea(this);

QVBoxLayout *layout = new QVBoxLayout(parent);
layout->addWidget(scrollArea);
scrollArea->setWidget(groupBox);
this->setLayout(layout);

this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->resize(1000,600);

ChrisW67
2nd February 2015, 20:31
Give the group box a size explicitly. The scroll area will not resize the widget, just allow you to pan about if it becomes larger than the viewport.