#include <QApplication>
#include <QTableWidget>
#include <QImage>
#include <QItemDelegate>
#include <QPainter>
const int num_images = 10;
const int img_width = 400;
const int img_height = 400;
public:
QImage newImage
("/path/to/image.jpg");
m_image = newImage.copy();
}
painter->drawImage(0,0, m_image);
//painter->setPen (QPen (Qt::red, 3));
//painter->drawEllipse(option.rect);
}
private:
};
int main(int argc, char **argv){
for (int i = 0; i < num_images; i++) {
tableWidget.setColumnWidth(i, img_width);
}
tableWidget.setRowHeight(0, img_height);
tableWidget.setItemDelegate(new Delegate(&tableWidget));
tableWidget.show();
return app.exec();
}
#include <QApplication>
#include <QTableWidget>
#include <QImage>
#include <QItemDelegate>
#include <QPainter>
const int num_images = 10;
const int img_width = 400;
const int img_height = 400;
class Delegate : public QItemDelegate {
public:
Delegate(QObject *parent=0) : QItemDelegate(parent){
QImage newImage("/path/to/image.jpg");
m_image = newImage.copy();
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
QItemDelegate::paint(painter, option, index);
painter->drawImage(0,0, m_image);
//painter->setPen (QPen (Qt::red, 3));
//painter->drawEllipse(option.rect);
}
private:
QImage m_image;
};
int main(int argc, char **argv){
QApplication app(argc, argv);
QTableWidget tableWidget(1, num_images);
for (int i = 0; i < num_images; i++) {
tableWidget.setColumnWidth(i, img_width);
}
tableWidget.setRowHeight(0, img_height);
tableWidget.setSelectionMode(QAbstractItemView::NoSelection);
tableWidget.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
tableWidget.setItemDelegate(new Delegate(&tableWidget));
tableWidget.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks