Results 1 to 9 of 9

Thread: Image Not displaying in Qlabel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2016
    Posts
    6
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Question Image Not displaying in Qlabel

    Hi guys..I am trying to display a series of image in qlabel..i dono where i am going wrong. when i click the qpushbutton it displays only the last image rather displaying from beginning. Below is my code

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. QLabel *FirstLabel = NULL;
    3. QLabel *SecondLabel = NULL;
    4. QLabel *ThirdLabel = NULL;
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8.  
    9. FirstLabel = new QLabel(this);
    10. FirstLabel->move(0,240);
    11. FirstLabel->resize(this->x()+400,this->y()+240);
    12. FirstLabel->show();
    13.  
    14. QPushButton *train_button = new QPushButton(this);
    15. train_button->setText(tr("something"));
    16. train_button->move(200,200);
    17. train_button->show();
    18.  
    19. connect(train_button, SIGNAL(clicked()),
    20. this, SLOT (PlayImage()));
    21. }
    22.  
    23. void MainWindow::PlayImage()
    24. {
    25. char* picture[5] = {"D://1.png","D://2.jpg","D://3.jpg","D://4.jpg","D://5.jpg"};
    26. for(int i = 0;i<=4 ; i++){
    27. QPixmap pixmapObject(picture[i]);
    28. FirstLabel->setPixmap(pixmapObject);
    29. update();
    30. }
    31. }
    32.  
    33. MainWindow::~MainWindow()
    34. {
    35. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QLabel>
    6. #include <string>
    7. #include <QPushButton>
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow(QWidget *parent = 0);
    15. ~MainWindow();
    16. void updateinfo();
    17. void Play();
    18.  
    19. public slots:
    20. void PlayImage();
    21. };
    22.  
    23. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.resize(800,480);
    9. w.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 26th July 2016 at 10:23. Reason: missing [code] tags

Similar Threads

  1. geting QLabel text ontop of other QLabel displaying image
    By krystosan in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2013, 17:35
  2. Qlabel not displaying images other than development machine
    By arunkumaraymuo1 in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2012, 14:52
  3. Problem with displaying image using Qlabel
    By deck99 in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 00:23
  4. Displaying an image
    By seltra in forum Newbie
    Replies: 2
    Last Post: 3rd October 2010, 19:30
  5. Replies: 6
    Last Post: 21st September 2009, 10:55

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
  •  
Qt is a trademark of The Qt Company.