April 8, 2012

enaud84 enaud84
Lab Rat
50 posts

Show a BMP image

 

Hi all,
I’m making a program to display a bmp image after a video ends ..
I wrote this code:

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <Phonon/VideoPlayer>
  4. #include <Phonon/MediaObject>
  5. #include <Phonon/MediaSource>
  6. #include <QString>
  7. #include <QImageReader>
  8. #include <QImage>
  9. #include <QGraphicsScene>
  10. #include <QGraphicsView>
  11. #include <QGraphicsPixmapItem>
  12. #include <QLabel>
  13.  
  14. MainWindow::MainWindow(QWidget *parent) :
  15.     QMainWindow(parent),
  16.     ui(new Ui::MainWindow)
  17. {
  18.     ui->setupUi(this);
  19.  
  20.  
  21.     Phonon::MediaObject *media = new Phonon::MediaObject(this);
  22.     media->setCurrentSource(Phonon::MediaSource(QString("/home/user/Desktop/video.avi")));
  23.     ui->videoPlayer->play(media->currentSource());
  24. }
  25.  
  26. MainWindow::~MainWindow()
  27. {
  28.     delete ui;
  29. }
  30.  
  31. void MainWindow::changeEvent(QEvent *e)
  32. {
  33.     QMainWindow::changeEvent(e);
  34.     switch (e->type()) {
  35.     case QEvent::LanguageChange:
  36.         ui->retranslateUi(this);
  37.         break;
  38.     default:
  39.         break;
  40.     }
  41. }
  42.  
  43. void MainWindow::on_videoPlayer_finished()
  44. {
  45.     ui->videoPlayer->close();
  46.     QGraphicsScene scene;
  47.     QGraphicsView view(&scene);
  48.     QGraphicsPixmapItem item(QPixmap("/home/user/Desktop/mappa.bmp"));
  49.     scene.addItem(&item);
  50.     view.show();
  51.  
  52. }

At finished i not view BMP image..

You can help me, please?
thanks at all

2 replies

April 9, 2012

joonhwan joonhwan
Lab Rat
94 posts

You didn’t position(and/or layout) your QGraphicsView in your central widget.
But, it seems to me even if you do that, the design would look bad in this case.

Though I did’t have any experience with phonon videoplayer widget class, it should be able to show any simple image file to its display or at least you can derive your own videoplayer class from it, and override QWidget::paintEvent() to show your image whenever you want.

 Signature 

joonhwan at gmail dot com

April 9, 2012

enaud84 enaud84
Lab Rat
50 posts

i’ve resolved thanks

 
  ‹‹ Qt QSqlDatabase ODBC and MySQL connection      Longform of Qt ››

You must log in to post a reply. Not a member yet? Register here!