Results 1 to 9 of 9

Thread: how to iterate over images and display them in sets of 8 (on QPushbuttons)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Red face how to iterate over images and display them in sets of 8 (on QPushbuttons)

    Hi everyone,
    I have a picture gallery application in which there are 8 QPushbuttons on top of which the pixmaps are set.On clicking the buttons(once the pixmaps are set on them),one can view them in enlarged form and do the usual things like rotate,zoomin/out etc.
    My problem is that I have got more than 8 images in the picture folder so,I want to iterate over the images and display them in batches of 8...meaning,first time,it shows the first 8 images then after a couple of secs it shows the next 8 and so on till all the pics have been shown and then it again starts from the first 8 and goes on(till the user clicks on any of the pics to enlarge it).
    I tried the following code:-
    Qt Code:
    1. void Photogallery::createbuttons() //function called from constructor to create the
    2. //8 pushbuttons
    3. {
    4. <<<<code to create the 8 buttons>>>
    5. QDir CurrentDirectory("/root/Desktop/photos"); //'photos' dir. contains pictures
    6. names= CurrentDirectory.entryList(QDir::Files|QDir::NoDotAndDotDot);
    7. //'names' is a Qstringlist variable
    8. timer=new QTimer(this);
    9. connect(timer,SIGNAL(timeout()),this,SLOT(update()));
    10. timer->start();
    11. }
    12.  
    13. void Mediagallery::update() //slot which sets up the images on buttons
    14. {
    15.  
    16. it= names.begin(); //'it' is QStringlist iterator
    17. int count=(names.size()/8);
    18.  
    19. for(int numimage=0;numimage<count;numimage++)
    20. {
    21. //first picture on first button.
    22. QString Imagename(*it5);
    23. firstImagepath = "/root/Desktop/photos/"+Imagename;
    24. QPixmap imagedisplay(firstImagepath);
    25. QIcon icon(imagedisplay);
    26. firstImage->setIcon(icon); //firstImage is a Qpushbutton
    27. connect(firstImage,SIGNAL(pressed()),this,SLOT(buttondown()));
    28. //buttondown() is a slot where I identify which button is clicked.
    29. //***********************************************************
    30. //second picture on second button
    31. it5++;
    32. QString Imagename2(*it5);
    33. secondImagepath = "/root/Desktop/photos/"+Imagename2;
    34. QPixmap imagedisplay2(secondImagepath);
    35. secondImage->setIcon(imagedisplay2);
    36. connect(secondImage,SIGNAL(pressed()),this,SLOT(buttondown()));
    37. //*************************************************************
    38. //third picture on third pushbutton
    39. it5++;
    40. QString Imagename3(*it5);
    41. thirdImagepath= "/root/Desktop/photos/"+Imagename3;
    42. QPixmap imagedisplay3(thirdImagepath);
    43. thirdImage->setIcon(imagedisplay3);
    44. connect(thirdImage,SIGNAL(pressed()),this,SLOT(buttondown()));
    45.  
    46. .........so on till 8th image is set.
    47.  
    48. QString numimagestr=QString::number(numimage);
    49. QMessageBox::information(NULL,"",numimagestr); //keeping count
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

    If I remove the 'QMessageBox' statement towards the end of the loop,all I get are eight empty pushbuttons (No pictures are set on them).If I keep the QMessageBox,I get the images in batches on the buttons(as expected) but,I cannot click on any of the pictures to enlarge it as the MessageBox keeps coming in the foreground.
    I want the pics to show in batches of 8 without the presence of the MessageBox.
    Any ideas on how to do that(maybe I need to change the logic) or use a Timer or something else at some point ....Need your advice on how to proceed.
    Thank you.
    Last edited by rishiraj; 7th May 2009 at 11:12.
    If everything seems to be going well, you have obviously overlooked something.

Similar Threads

  1. Can QTextBrowser display remote images?
    By golnaz in forum Newbie
    Replies: 1
    Last Post: 21st January 2009, 13:45
  2. How to display a images use mosaic foramt?
    By longtrue in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 08:40
  3. Display multiple Images in a widget
    By jeetu_happy in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2007, 11:24
  4. How to display images in QTextBrowser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 08:58

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.