By default, a QListView class will request Qt::DisplayRole and Qt::DecorationRole to display text and a picture for each item. Thus, we already have a visual result, for free, that looks like this:
However, our Gallery application deserves better thumbnail rendering. Hopefully, we can easily customize it using the view's delegate concept. A QListView class provides a default item rendering. We can do our own item rendering by creating a class that inherits QStyledItemDelegate. The aim is to paint your dream thumbnails with a name banner, like in the following screenshot:
Let's take a look at PictureDelegate.h:
#include <QStyledItemDelegate> class PictureDelegate : public QStyledItemDelegate { Q_OBJECT public: PictureDelegate(QObject* parent = 0); void paint(QPainter* painter, const QStyleOptionViewItem...