Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: Image content as variable  (Read 8140 times)

maurosanjo

  • Newbie
  • *
  • Posts: 10
    • View Profile
Image content as variable
« on: December 01, 2016, 11:34:30 pm »
Hi there,

In the way LimeReport was designed the image can be static and also associated with a DataSoure.Field. But imagine we have a custom report in which we need to programatically change the company logo.
Is there any way?
If not, would be interesting if we could treat the image as a text field and set a Report Variable to it?

Congrats on the Report Designer tool, the best look'n feel and usability I found among Qt report solutions  :D
Regards

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Image content as variable
« Reply #1 on: December 02, 2016, 02:34:37 am »
Hi !
Thank you for your kind words to the LimeReport :)
You can use TextItem for printing images from application resources. To do this you should allowHtml in TextItem and specify the path to the resource like this <img source=":/report//images/pin"/>
« Last Edit: December 02, 2016, 03:19:27 am by Arin Alex »

maurosanjo

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Image content as variable
« Reply #2 on: December 05, 2016, 08:14:15 pm »
Hello,

Thanks. I tried that, its not as clean as what you did on your categories example. Using Image we can take advantage of scale, keepAspectRation, etc.

Something is strange, if I put a Image on Data Band and set Resource and Field on it, on the slot & signal mechanism I can set a QImage to data and it works fine. But if I put the Image on the group header, of footer, no matter if I put it on columnData or not, it gets fetched (more than once by the way) on the callback function but setting QImage to data (QVariant) does not work. Is it a bug or a limitation?

Regards

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Image content as variable
« Reply #3 on: December 06, 2016, 12:58:19 am »
Hi !
Thanks. I tried that, its not as clean as what you did on your categories example. Using Image we can take advantage of scale, keepAspectRation, etc.
I have added resourcePath property to ImageItem. From now you can use something like this ":report/images/pin" in this property

Something is strange, if I put a Image on Data Band and set Resource and Field on it, on the slot & signal mechanism I can set a QImage to data and it works fine. But if I put the Image on the group header, of footer, no matter if I put it on columnData or not, it gets fetched (more than once by the way) on the callback function but setting QImage to data (QVariant) does not work. Is it a bug or a limitation?

It's very strange :) I have tried to repeat that case but I didn't get same result.

I have used next callback slot :
Code: [Select]
void MainWindow::slotOneSlotDS(LimeReport::CallbackInfo info, QVariant &data)
{
    QStringList columns;
    columns << "Name" << "Value" << "Image";
    switch (info.dataType) {
            case LimeReport::CallbackInfo::RowCount:
                data = 4;
                break;
            case LimeReport::CallbackInfo::ColumnCount:
                data = columns.size();
                break;
            case LimeReport::CallbackInfo::IsEmpty:
                data = false;
                break;
            case LimeReport::CallbackInfo::ColumnHeaderData: {
                data = columns.at(info.index);
                break;
            }
            case LimeReport::CallbackInfo::ColumnData:
                if (info.columnName == "Image")
                    data = QImage(":/report//images/logo32");
                else {
                    data = info.columnName+" "+QString::number(info.index);
                }
                break;
            default: break;
        }
}

and attached report
and I got the result that you can see on the attached image

[вложение удалено администратором]

maurosanjo

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Image content as variable
« Reply #4 on: December 06, 2016, 02:08:55 pm »
Oh man, so sorry, it was a problem on my resource images. Indeed it is working :P Thanks

cwl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Image content as variable
« Reply #5 on: October 26, 2018, 09:14:37 am »
hi,could you give an example for this! thank you very much

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Image content as variable
« Reply #6 on: October 30, 2018, 12:07:05 am »
Hi!
What kind of example do you want? If you want to know how to use an image from the application resources here is an example: 
1. Allow HTML in TextItem
2. Put this sample string into the item content
Code: [Select]
<img source=":/report//images/pin" width="100" height="100" />3. Run the report :)

cwl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Image content as variable
« Reply #7 on: October 30, 2018, 09:43:22 am »
hi!Alex! thanks for your reply. Now i have another question, could current designer design a report that content text, table and image.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Image content as variable
« Reply #8 on: October 30, 2018, 05:32:04 pm »
cwl
Yes, it can.

cwl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Image content as variable
« Reply #9 on: October 31, 2018, 04:16:30 am »
Alex, thank you and your guys good job,thank you very much, and hope the project open source all the way.