Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Qt widget to use for implementing image thumbnail browser (displaying tiles)?

Tags:

widget

qt

I'm looking to essentially replicate this:

enter image description here

What is the most appropriate Qt container widget for displaying my custom widgets containing image+subscript? I'm looking at QTableView and it seems to be supposed to have a set number of rows/columns, while I would like my program to change layout depending on window width (so that there is no horizontal scroll), and adding new widget should be done with addWidget(QWidget * w), not setWidget(int row, int column, QWidget * w). Is there a better component for this than QTableView (which requires much coding for my task)?

like image 289
Violet Giraffe Avatar asked Jan 01 '13 22:01

Violet Giraffe


People also ask

How do I display an image in Qt widget?

There isn't a widget specifically made for displaying images, but this can be done with the label widget. We do this with the pixmap property. QPixmap pic("/path/to/your/image"); ui->label->setPixmap(pic);


1 Answers

You should use QListWidget (or QListView and subclass QAbstractItemModel) and set it's view mode to IconMode.

Example :

m_listeWidget->setViewMode(QListWidget::IconMode);  m_listeWidget->setIconSize(QSize(200,200));  m_listeWidget->setResizeMode(QListWidget::Adjust);  m_listeWidget->addItem(new QListWidgetItem(QIcon("../earth.jpg"),"Earth")); m_listeWidget->addItem(new QListWidgetItem(QIcon("../tornado.jpg"),"Tornado")); m_listeWidget->addItem(new QListWidgetItem(QIcon("../ics.jpg"),"Wallpaper")); 

Result :

enter image description here

like image 153
Youssef Bouhjira Avatar answered Sep 22 '22 09:09

Youssef Bouhjira