PDA

View Full Version : Problem in displaying images on the clicked(qmodelindex) SIGNAL



kamlmish
27th December 2010, 09:55
Hi
I have a slot function "displayitem(const QModelIndex& index)" to display the images .



void eBeamTree::displayitem(const QModelIndex& index)
{
QString path = mod->filePath(index);
QDir dir;
dir.setPath(path);
QImage thumb, tmp;
int sizeW = 20;
int sizeH = 20;
QStringList listfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i=0;i<listfiles.count();i++)
{
QString filename = listfiles.at(i);
QString filepath = dir.absoluteFilePath(filename);
bool x = tmp.load(filepath);
if(x == true)
{
thumb = (tmp.scaled( 120, 120 ).scaled( sizeW, sizeH, Qt::IgnoreAspectRatio )); //two passes
frame->model->setData(frame->model->index( i, 0 ), thumb, Qt::DecorationRole );
frame->model->setData(frame->model->index(i,1),filename,Qt::DisplayRole);
}

}
frame->treeview->setModel(mod);
frame->treeview->setHeaderHidden(true);
frame->treeview->show();

}

Declaration of the class eBeamTree and FrameDisplay is provided



class eBeamTree: public QTreeWidget
{
Q_OBJECT
public:
eBeamTree(QWidget* parent=0);
~eBeamTree();

public:
void populate();
void DockSize();
void FloatSize();

public slots:
void displayitem(const QModelIndex& index);

public:
QDirModel* mod;
QTreeView* view;
QDir eBeamDir;
FrameDisplay* frame;

};




class FrameDisplay: public QListWidget
{
Q_OBJECT
public:
FrameDisplay(QWidget* parent = 0);
~FrameDisplay();
public:
void DockSize();
void FloatSize();

public:
QDirModel *model;
QTreeView* treeview;

};


I am able to debug the code and check the list of files and filenames , but when running the app, images do not display .
As per the image, the basic idea is when a user clicks any item on the tree (left side)
images under that particular child item should get displayed

franz
27th December 2010, 19:40
According to the documentation (http://doc.qt.nokia.com/latest/qt.html#ItemDataRole-enum), data for the Qt::DecorationRole should be a QColor, QIcon or QPixmap. You should probably pass the image's pixmap instead of the image itself.

kamlmish
28th December 2010, 09:59
I am able to display the images , but issue now is that
I need to align the display of images accoridng to the size of the frame.
If I use QPixmap, QIcon or QColor, the loading of images takes lot of time as compared to QImage