Using icons with QTreeWidgetItem
-
I have an application using a QTreeWidget with tree nodes (QTreeWidgetItem). I would like to add icons to the nodes in my tree. I can get this to work using a file:
[code]
item->setIcon(0, *(new QIcon("test1.gif")));
[/code]I have a resource file where I have added all the images I want to use for icons. How can I set the icon by referencing the resource file rather than directly referencing the image files?
Thanks for any guidance.
-
For some reason I can't get this to work.
My resource file contains:
[code]
<file>Resources/cirsqr/test1.gif</file>
[/code]To be more complete, here is a larger section of the resource file:
[code]
<qresource prefix="/cirsqr">
<file>Resources/cirsqr/cir gray - sq gray.gif</file>
<file>Resources/cirsqr/cir gray - sq green.gif</file>
<file>Resources/cirsqr/cir gray - sq red.gif</file>
<file>Resources/cirsqr/cir gray - sq yellow.gif</file>
<file>Resources/cirsqr/cir green - sq gray.gif</file>
<file>Resources/cirsqr/cir green - sq green.gif</file>
<file>Resources/cirsqr/cir green - sq red.gif</file>
<file>Resources/cirsqr/cir green - sq yellow.gif</file>
<file>Resources/cirsqr/cir red - sq gray.gif</file>
<file>Resources/cirsqr/cir red - sq green.gif</file>
<file>Resources/cirsqr/cir red - sq red.gif</file>
<file>Resources/cirsqr/cir red - sq yellow.gif</file>
<file>Resources/cirsqr/cir yellow - sq gray.gif</file>
<file>Resources/cirsqr/cir yellow - sq green.gif</file>
<file>Resources/cirsqr/cir yellow - sq red.gif</file>
<file>Resources/cirsqr/cir yellow - sq yellow.gif</file>
<file>Resources/cirsqr/test2.gif</file>
<file>Resources/cirsqr/test1.gif</file>
</qresource>
[/code]My code tries to reference this as follows:
[code]
item->setIcon(0, *(new QIcon(":/Resources/cirsqr/test1.gif")));
[/code]The icon is not displayed, which indicates it is not finding the test1.gif image. Do you see anything that I am doing wrong here?
Thanks again.
-
@
<RCC>
<qresource prefix="/Resources/cirsqr">
<file>test1.gif</file>
</qresource>
</RCC>
@On my dialog:
@
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->pushButton->setIcon(QIcon(":Resources/cirsqr/test1.gif"));
}
@Here is a screenshot:
https://picasaweb.google.com/lh/photo/Ba7cJDkearL4oTOlnIipqdMTjNZETYmyPJy0liipFm0?feat=directlink
-