View Full Version : Custom active fields inside a QGraphicsTextItem

4th February 2013, 23:55
Hello, I am using some QGraphicsTextItem that need to embed inside of it "special" tags. These tags should be parsed and postprocessed, and the real displayed text should change in response to some action (the idea is the same of Word "fields").
I am currently using the <a> tag with some special URL in its href attribute, which can be easily parsed and identified, and the text surrounded by <a> and </a> gets updated. I have devised this so far since the user might want to modify, save, and reload the text, and the special field must be kept. Just to finish with an example:

<a href="date">***</a>

after postprocessing becomes

<a href="date">2013/02/04</a>

I am kindly asking you here if there is a less cumbersome method to carry this task out, any idea is welcome, thank you.

Santosh Reddy
13th February 2013, 10:15
I guess you are doing all this with a QGraphicsTextItem derived class item, if not I see that as one nice approach.

You could use the same way QString does it, just use %1, %2... place holders/tags/fields, and later process them using the QString::arg() functions.

Raw Text: "Message to %3: %1 %4 very Good Day for %2 for %3"

%1 = Today
%2 = Swimming
%3 = Smith
%4 = is
Processed Text: "Message to Smith: Today is very Good Day for Swimming for Smith"

%1 = Next Sunday
%2 = Hiking
%3 = Tom
%4 = will be
Processed Text: "Message to Tom: Next Sunday will be very Good Day for Hiking for Tom"

14th February 2013, 00:12
Hello Santosh, thank you for your confirmation on the validity of this method.
The other method you suggest is fine, but the problem is: what should the end user edit? He/she should not know anything about %1 %2 etc. that are interspersed in the text. He should just see the final/computed result and be aware that that word is "particular". Moreover, I have the particularity that the user edits all this text in WYSIWYG way, with all the formatting of italic, bold, etc.