I've code this below and works. When I selected (only one click) a fileName in myFileDialog, on the right, in the preview box appear if the file selected is a pixmap or not; I'd like, when I click, show in preview box, the preview of image (the image). How to do? Thanks
Qt Code:
  1. class Preview : public QLabel, public QFilePreview {
  2. public:
  3. Preview( QWidget *parent=0 ) : QLabel( parent ) {}
  4.  
  5. void previewUrl( const QUrl &u )
  6. {
  7. QString path = u.path();
  8. QPixmap pix( path );
  9. if ( pix.isNull() ) {
  10. setText( "This is not a pixmap" );
  11. } else {
  12.  
  13. setText( "This is a pixmap" );
  14. }
  15. }
  16. };
  17.  
  18. Preview* p = new Preview;
  19. myFileDialog* myFd = new myFileDialog(this,"",)
  20. myFd->setContentsPreviewEnabled( TRUE );
  21. myFd->setContentsPreview( p, p );
  22. if ( myFd->exec() == QDialog::Accepted )
  23. file = myFd->selectedFile();
To copy to clipboard, switch view to plain text mode