Results 1 to 12 of 12

Thread: preview file dialog

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default preview file dialog

    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 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    Qt Code:
    1. if ( pix.isNull() ) {
    2. setText( "This is not a pixmap" );
    3. } else {
    4. setPixmap( pix );
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: preview file dialog

    Thanks, it works; I'm trying to change it size; with this works, but happen this:
    Qt Code:
    1. pix.resize(QSize(150,150));
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    read the docs for QPixmap::resize(). It does not resize the image, jsut the size of the pixmap. You will need to create a QImage, scale it with QImage::scale() and create a pixmap from that.
    Save yourself some pain. Learn C++ before learning Qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    Use this:
    void QLabel::setScaledContents ( bool )
    Sets whether the label will scale its contents to fill all available space. See the "scaledContents" property for details.

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    Quote Originally Posted by jacek
    Use this:
    Yes of of course. This is the simpler solution!
    Save yourself some pain. Learn C++ before learning Qt.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: preview file dialog

    thanks, it works; but is it possible repeat more times the same QImage onto a pixmap?
    Regards

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: preview file dialog

    I don't understand how you say me use QLabel for my aim; beyond this, I used pixmap; and I think using qlabel (?) my problem will persists: my image appears distorted (texture 32x32). Am I wrong? (I'd like show it more large, for this I thinked to repeat an QImage on a QPixmap) Thanks
    Last edited by mickey; 20th April 2006 at 22:02.
    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    Quote Originally Posted by mickey
    I don't understand how you say me use QLabel for my aim; beyond this, I used pixmap; and I think using qlabel (?) my problem will persists: my image appears distorted (texture 32x32). Am I wrong? (I'd like show it more large, for this I thinked to repeat an QImage on a QPixmap) Thanks
    Ah, the aspect ratio of your image is being distorted. In this case, you should create a QImage and scale it up to the correct size, while retaining the aspect ratio: Something like:

    Qt Code:
    1. void previewUrl(const QUrl& rUrl)
    2. {
    3. QString path = rUrl.path();
    4. QImage im(path);
    5. if (im.isNull())
    6. {
    7. setText( "This is not a pixmap" );
    8. }
    9. else
    10. {
    11. im = im.smoothScale(width(), height(), QImage::ScaleMin);
    12. setPixmap(QPixmap(im));
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    If you just want to tile the image, use this instead:

    Qt Code:
    1. void previewUrl(const QUrl& rUrl)
    2. {
    3. QString path = rUrl.path();
    4. QPixmap p(path);
    5. if (p.isNull())
    6. {
    7. setText( "This is not a pixmap" );
    8. }
    9. else
    10. {
    11. setPaletteBackgroundPixmap(p);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Chicken Blood Machine; 21st April 2006 at 00:29.
    Save yourself some pain. Learn C++ before learning Qt.

  10. #10
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: preview file dialog

    with pallette seems better....but happen this. and when I select a non-pixmap, the preview widget don't change...
    Attached Images Attached Images
    Regards

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preview file dialog

    Quote Originally Posted by mickey
    with pallette seems better....but happen this. and when I select a non-pixmap, the preview widget don't change...
    Because you must restore the original palette.

  12. #12
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: preview file dialog

    the very problem isn't that. If I selected a pixmap happen what you see in the pictures....the text isn't clear; and if I put
    Qt Code:
    1. setText("" );
    2. setPaletteBackgroundPixmap(pix);
    To copy to clipboard, switch view to plain text mode 
    happen that my background change in a tiny column;
    Regards

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. File Dialog / Network Protocols in QT4
    By themolecule in forum Qt Programming
    Replies: 6
    Last Post: 10th September 2007, 07:40
  3. File Open dialog with preview?
    By will49 in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 18:08
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.