Results 1 to 3 of 3

Thread: Problem in displaying images on the clicked(qmodelindex) SIGNAL

  1. #1
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Problem in displaying images on the clicked(qmodelindex) SIGNAL

    Hi
    I have a slot function "displayitem(const QModelIndex& index)" to display the images .

    Qt Code:
    1. void eBeamTree::displayitem(const QModelIndex& index)
    2. {
    3. QString path = mod->filePath(index);
    4. QDir dir;
    5. dir.setPath(path);
    6. QImage thumb, tmp;
    7. int sizeW = 20;
    8. int sizeH = 20;
    9. QStringList listfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
    10. for(int i=0;i<listfiles.count();i++)
    11. {
    12. QString filename = listfiles.at(i);
    13. QString filepath = dir.absoluteFilePath(filename);
    14. bool x = tmp.load(filepath);
    15. if(x == true)
    16. {
    17. thumb = (tmp.scaled( 120, 120 ).scaled( sizeW, sizeH, Qt::IgnoreAspectRatio )); //two passes
    18. frame->model->setData(frame->model->index( i, 0 ), thumb, Qt::DecorationRole );
    19. frame->model->setData(frame->model->index(i,1),filename,Qt::DisplayRole);
    20. }
    21.  
    22. }
    23. frame->treeview->setModel(mod);
    24. frame->treeview->setHeaderHidden(true);
    25. frame->treeview->show();
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 
    Declaration of the class eBeamTree and FrameDisplay is provided

    Qt Code:
    1. class eBeamTree: public QTreeWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. eBeamTree(QWidget* parent=0);
    6. ~eBeamTree();
    7.  
    8. public:
    9. void populate();
    10. void DockSize();
    11. void FloatSize();
    12.  
    13. public slots:
    14. void displayitem(const QModelIndex& index);
    15.  
    16. public:
    17. QDirModel* mod;
    18. QTreeView* view;
    19. QDir eBeamDir;
    20. FrameDisplay* frame;
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class FrameDisplay: public QListWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. FrameDisplay(QWidget* parent = 0);
    6. ~FrameDisplay();
    7. public:
    8. void DockSize();
    9. void FloatSize();
    10.  
    11. public:
    12. QDirModel *model;
    13. QTreeView* treeview;
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 

    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
    Attached Images Attached Images
    Last edited by kamlmish; 27th December 2010 at 10:04.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in displaying images on the clicked(qmodelindex) SIGNAL

    According to the documentation, data for the Qt:ecorationRole should be a QColor, QIcon or QPixmap. You should probably pass the image's pixmap instead of the image itself.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Problem in displaying images on the clicked(qmodelindex) SIGNAL

    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

Similar Threads

  1. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  2. Emit clicked( QModelIndex &) from a QTreeView?
    By Ran in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 04:42
  3. Problem with displaying jpeg and gif images, in QT4
    By node_ex in forum Installation and Deployment
    Replies: 1
    Last Post: 23rd September 2008, 15:29
  4. Replies: 6
    Last Post: 5th December 2007, 22:41
  5. QTreeView::doubleClicked(const QModelIndex&) signal
    By Vladimir in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2007, 09:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.