Results 1 to 9 of 9

Thread: QListWidget doesn't show icons

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QListWidget doesn't show icons

    Hi to all,
    I built a dialog with designer to create an audiotrack list.
    With the dialog the user can add/remove audio tracks. In the dialog there is a QListWidget so the user can see the list of the sounds he added.
    I would show an "audio" icon near the name of the audio track but it doesn't work.
    I set the viewmode to QListView::IconMode so:

    Qt Code:
    1. ui.trackList->setViewMode(QListView::IconMode);
    To copy to clipboard, switch view to plain text mode 

    but it doesn't work. I only see the name of the tracks and not the icon.
    This is the ctor of the dialog:

    Qt Code:
    1. TrackListDlg::TrackListDlg(QStringList& trackList_, QString& srcDir_, QWidget *parent)
    2. : QDialog(parent),
    3. m_trackList(trackList_),
    4. m_srcDir(srcDir_)
    5. {
    6. ui.setupUi(this);
    7.  
    8. ui.trackList->setSortingEnabled( true );
    9. ui.trackList->setViewMode(QListView::IconMode); //<-- doesn't work
    10. ui.trackList->setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
    11.  
    12. for (int i = 0; i < m_trackList.size(); ++i)
    13. {
    14. QFileInfo fi( m_trackList.at(i) );
    15. ui.trackList->addItem(fi.fileName());
    16. }
    17.  
    18. connect( ui.cancelBtn, SIGNAL( released() ), this, SLOT( slotCancel() ) );
    19. connect( ui.addBtn, SIGNAL( released() ), this, SLOT( slotAdd() ) );
    20. }
    To copy to clipboard, switch view to plain text mode 

    The audio tracks can only be *.mp3 or *.wav and I think windows should set the right icon for such files or I'm wrong?
    Do I have to set the icons manually?

    I hope to get help.
    Best Regards,
    Franco
    Franco Amato

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QListWidget doesn't show icons

    Are you sure that your icons appear properly someshere else? I mean did you give the correct path for your icon files?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget doesn't show icons

    The audio tracks can only be *.mp3 or *.wav and I think windows should set the right icon for such files or I'm wrong?
    Do I have to set the icons manually?
    You have to set icons manually.
    setViewMode(QListView::IconMode); says to display only the icons that you have set.

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget doesn't show icons

    Quote Originally Posted by zgulser View Post
    Are you sure that your icons appear properly someshere else? I mean did you give the correct path for your icon files?
    I don't understand. It shouldn't be automatic from window? Or I have to do it manually?

    For example when I exec a QFileDialog::getOpenFileNames dialog, the dialog show a list of files with relative icon,
    and I think this is managed by windows.

    Give a look at the screen shotimage.jpg it show an icon and the name of the file.

    I would do the same.

    Regards
    Last edited by franco.amato; 12th March 2010 at 06:59.
    Franco Amato

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QListWidget doesn't show icons

    I see..I don't know the exact solution but at least I can suggest you to implement this from the source through setIcon method.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget doesn't show icons

    From the docs for getOpenFileNames -
    On Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog.
    So you see , its the native dialog that shows the icons. If you are showing your dialog / view, you will need to set the icon manually.
    Without setting icon, how do you expect the view to draw the icon itself ?

  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget doesn't show icons

    Quote Originally Posted by aamer4yu View Post
    From the docs for getOpenFileNames -

    So you see , its the native dialog that shows the icons. If you are showing your dialog / view, you will need to set the icon manually.
    Without setting icon, how do you expect the view to draw the icon itself ?
    maybe with a QMiracle?
    Franco Amato

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget doesn't show icons

    There is a QFileIconProvider or QStyle::standardIcon() but I guess that are not the icons you are searching for.

  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget doesn't show icons

    Quote Originally Posted by Lykurg View Post
    There is a QFileIconProvider or QStyle::standardIcon() but I guess that are not the icons you are searching for.
    Thank you very much Lykurg, I'll let the dialog without icons.

    Regards
    Franco Amato

Similar Threads

  1. Replies: 1
    Last Post: 22nd February 2010, 10:53
  2. Icons in a QListWidget
    By LuHe in forum Qt Tools
    Replies: 10
    Last Post: 30th January 2010, 04:19
  3. Where to get Icons from
    By pospiech in forum General Discussion
    Replies: 4
    Last Post: 19th December 2008, 21:14
  4. Replies: 2
    Last Post: 11th September 2007, 08:57
  5. how to show richtext and icons in one widget in QT2
    By pencilren in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2007, 10:30

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.