Results 1 to 2 of 2

Thread: Preview Thumbnail of images in Custom QFileDialog

  1. #1
    Join Date
    Jun 2010
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Preview Thumbnail of images in Custom QFileDialog

    I know this has been asked many times but it hasn't been fully answered. I have also googled for quite some time now but haven't found anything helpfull yet.

    So basically from the documentation I understand I need an Item Delegate to personalize the preview icon. Thats ok. So I did this test:

    Qt Code:
    1. class PixmapPreviewDelegate : public QStyledItemDelegate
    2. {
    3. public:
    4. PixmapPreviewDelegate(QObject *parent = 0) :
    5. QStyledItemDelegate(parent)
    6. {
    7. }
    8.  
    9. void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
    10. painter->drawText(
    11. option.rect,
    12. displayText(index.data(), QLocale::system()),
    13. option.displayAlignment
    14. );
    15.  
    16. QStyleOptionViewItem auxOpcion = option;
    17. auxOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    18. auxOption.rect.setWidth(auxOption.rect.height());
    19. painter->drawPixmap(auxOption.rect, QPixmap(":images/test.png"));
    20. }
    21. };
    To copy to clipboard, switch view to plain text mode 

    That worked ok. But I found I had lost all default styles (files where not highlighted when selected), which was unacceptable. Secondly, since the index data has only the file name I couldn't use it in the Pixmap constructor. So I need to constantly tell the delegate the current folder the user is seeing? Isn't this just crazy?

    Then I thought I could just change the data's Qt:: DecorationRole in order to change the icon, but didn't know how to do this?
    This doesn't seem to work:
    Qt Code:
    1. void setModelData(QWidget * widget, QAbstractItemModel* item, const ModelIndex& index ) const {
    2. Q_UNUSED(widget);
    3. qDebug() << "setModelData";
    4. item->setData(index, QIcon(":images/test.png"), Qt::DecorationRole);
    5. }
    To copy to clipboard, switch view to plain text mode 


    I'm really stuck with this.

    Thanks for any help.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Preview Thumbnail of images in Custom QFileDialog

    You could use Qt3's file dialog, which provided the ability to add a preview widget of your own. Much, much simpler than the approach you're taking.

    You could also lobby the Trolls to do the right thing and bring this feature back. It's absence is inexcusable, and the Qt file dialog took a giant step backward when it was removed.

    Or, you could examine the UI file from the Qt file dialog source and insert your own preview widget into the layout, connecting it to the signals that already exist denoting changing selections. You can do this at runtime, if you like, with the assumption that the layout naming will remain constant in the future. Not a great solution, but better than nothing until the Trolls come to their senses.

Similar Threads

  1. How can i have a QFileDialog with a preview of the picture?
    By Bong.Da.City in forum Qt Programming
    Replies: 10
    Last Post: 13th September 2016, 17:24
  2. QPolygonF preview for a custom QGraphicsItem
    By matteo.boscolo in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2010, 16:04
  3. how to browse images in thumbnail view?
    By zl2k in forum Qt Programming
    Replies: 12
    Last Post: 23rd April 2009, 02:20
  4. Open/Save dialog with images preview
    By mchara in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2007, 07:25
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

Tags for this Thread

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.