PDA

View Full Version : QListWidget doesn't show icons



franco.amato
12th March 2010, 06:40
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:


ui.trackList->setViewMode(QListView::IconMode);

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


TrackListDlg::TrackListDlg(QStringList& trackList_, QString& srcDir_, QWidget *parent)
: QDialog(parent),
m_trackList(trackList_),
m_srcDir(srcDir_)
{
ui.setupUi(this);

ui.trackList->setSortingEnabled( true );
ui.trackList->setViewMode(QListView::IconMode); //<-- doesn't work
ui.trackList->setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");

for (int i = 0; i < m_trackList.size(); ++i)
{
QFileInfo fi( m_trackList.at(i) );
ui.trackList->addItem(fi.fileName());
}

connect( ui.cancelBtn, SIGNAL( released() ), this, SLOT( slotCancel() ) );
connect( ui.addBtn, SIGNAL( released() ), this, SLOT( slotAdd() ) );
}

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

zgulser
12th March 2010, 06:43
Are you sure that your icons appear properly someshere else? I mean did you give the correct path for your icon files?

aamer4yu
12th March 2010, 06:51
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.

franco.amato
12th March 2010, 06:52
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 shot4402 it show an icon and the name of the file.

I would do the same.

Regards

zgulser
12th March 2010, 07:03
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.

aamer4yu
12th March 2010, 07:09
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 ?

franco.amato
16th March 2010, 06:21
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?

Lykurg
16th March 2010, 09:19
There is a QFileIconProvider or QStyle::standardIcon() but I guess that are not the icons you are searching for.

franco.amato
16th March 2010, 14:15
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