Results 1 to 5 of 5

Thread: Reading PDFs from a directory

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Reading PDFs from a directory

    I am hoping to get some help here guys. I am developing this program that reads and displays pdf documents from a directory. The program does not actually open the pdf documents, it just displays them in list format in a QListView. My problem is that the program reads only the title/name of the pdf documents and leaves the icon next to the title. The picture on the left, shows a screenshot of how the program reads and displays the pdf documents (without the icons). The picture on the right is how the pdf documents are displayed in the directory and that is how I would like them to be displayed by my program. Untitled.jpgCapture.PNG

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Reading PDFs from a directory

    If you are feeding your QListView from a model derived from QAbstractItemModel, then you need to implement the Qt::DecorationRole inside your model's data() method (QAbstractItemModel::data()) and supply the appropriate QIcon. QListView doesn't know these are PDF document names. The directory view asks the OS for the icon associated with entries in a directory, so that's why you see them there.

    It's hard to see because your screenshot is so tiny, but it also looks like your filenames are aligned horizontal center in each column. If you don't want that, then you also need to implement the Qt:: AlignmentRole in the data() method, and return Qt:: AlignLeft | Qt:: AlignVCenter.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    ayanda83 (1st October 2016)

  4. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading PDFs from a directory

    The directory view asks the OS for the icon associated with entries in a directory, so that's why you see them there.
    Is there no way I get my program to ask the OS for an associated icon to a file instead of supplying it myself?

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Reading PDFs from a directory

    Is there no way I get my program to ask the OS for an associated icon to a file instead of supplying it myself?
    I looked for that as I was making my original answer. QFileSystemModel has a QFileSystemModel::FileIconRole that gets mapped to the DecorationRole. QFileDialog apparently knows to ask for this (along with some of the Qt:: UserRole extras that the file system model provides). I thought QFileInfo might serve up the icon, but it doesn't. I think you'll have to look into the QFileSystemModel source code to find out what it is doing.

    You can download the official PDF icon from Adobe here.

    Edit: Aha! There is a QFileIconProvider class!
    Last edited by d_stranz; 1st October 2016 at 23:42.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #5
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading PDFs from a directory

    Thank you very much, you've been a great help. I'm going to check-out QFileIconProvider, I'm pretty sure this will solve my problem.

Similar Threads

  1. Replies: 0
    Last Post: 19th February 2013, 17:46
  2. get .pro directory
    By Alnitak in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2010, 19:43
  3. Removing a directory entirely
    By Barry79 in forum Qt Programming
    Replies: 0
    Last Post: 11th May 2009, 16:09
  4. Specify the DLL directory
    By Nyphel in forum Newbie
    Replies: 6
    Last Post: 27th April 2007, 15:29
  5. Drag and Drop PDFs
    By kroenecker in forum Qt Programming
    Replies: 7
    Last Post: 4th July 2006, 10:56

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.