29

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)?

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335

2 Answers2

56

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

Youssef Bouhjira
  • 1,599
  • 2
  • 22
  • 38
  • 1
    That indeed works. I wanted to use my own widget as list item, but any working solution is better than any non-working one, I guess :) – Violet Giraffe Jan 05 '13 at 12:36
1

definitly QTableView, Using custom itemDelegate to present every block, implements the custom widget to display the Image and Text Title

yodabox
  • 175
  • 2
  • 7
  • Not QTableWidget/QListWidget? I'm currently trying QListWidget but aving trouble making it display my widgets at all. QTableView would mean I have to handle resizes manually to change the number of columns appropriately, seems too much of a work. Also, why do I need a delegate? All I want to do is display static picture+text widgets, Is there no easier way to achieve that? – Violet Giraffe Jan 04 '13 at 11:35
  • The advantage of QTableView is the free to handle the data model and ItemWidget, so nedd your custom implements of datamodel and itemDelegate class. It seem much work to do,but give you more convenience.By using itemDelegate,you can easy custom browser sytle and title style ,and so on. I did this Myself in my app. – yodabox Jan 06 '13 at 07:51