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
class Preview
: public QLabel,
public QFilePreview
{public:
void previewUrl
( const QUrl &u
) {
if ( pix.isNull() ) {
setText( "This is not a pixmap" );
} else {
setText( "This is a pixmap" );
}
}
};
Preview* p = new Preview;
myFileDialog* myFd = new myFileDialog(this,"",)
myFd->setContentsPreviewEnabled( TRUE );
myFd->setContentsPreview( p, p );
if ( myFd
->exec
() == QDialog::Accepted ) file = myFd->selectedFile();
class Preview : public QLabel, public QFilePreview {
public:
Preview( QWidget *parent=0 ) : QLabel( parent ) {}
void previewUrl( const QUrl &u )
{
QString path = u.path();
QPixmap pix( path );
if ( pix.isNull() ) {
setText( "This is not a pixmap" );
} else {
setText( "This is a pixmap" );
}
}
};
Preview* p = new Preview;
myFileDialog* myFd = new myFileDialog(this,"",)
myFd->setContentsPreviewEnabled( TRUE );
myFd->setContentsPreview( p, p );
if ( myFd->exec() == QDialog::Accepted )
file = myFd->selectedFile();
To copy to clipboard, switch view to plain text mode
Bookmarks