Qt-interest Archive, March 2002
Rich Text versus Plain Text
Message 1 in thread
Hi,
I have a QTextEdit fill withh tagged rich text. Is their any way to
acquire back from the QTextEdit the text it is actually displaying? -
Unfortunately, only using the 'text()' function returns that text mixed
in with their original tags. I want just the plain text involved without
any tags.
Ideas?
Nicholas.
Message 2 in thread
On Fri 15. March 2002 06:56, you wrote:
> Hi,
> I have a QTextEdit fill withh tagged rich text. Is their any way to
> acquire back from the QTextEdit the text it is actually displaying? -
> Unfortunately, only using the 'text()' function returns that text mixed
> in with their original tags. I want just the plain text involved without
> any tags.
Try this:
QString DeleteTags( const QString& a_rString )
{
int lessPos = a_rString.find( '<' );
int morePos;
if ( lessPos != -1 )
{
morePos = a_rString.find( '>', lessPos );
return morePos != -1
? a_rString.left(lessPos) + DeleteTags( a_rString.mid(morePos+1) )
// Look for other tags
: a_rString
// Quite strange - non-closed tag, but we have to handle it somehow.
;
}
else
return a_rString;
}
--
[ signature omitted ]
Message 3 in thread
Mariusz Lotko <mariusz.lotko@pruftechnik.com.pl> wrote:
>On Fri 15. March 2002 06:56, you wrote:
>> Hi,
>> I have a QTextEdit fill withh tagged rich text. Is their any way to
>> acquire back from the QTextEdit the text it is actually displaying? -
>> Unfortunately, only using the 'text()' function returns that text mixed
>> in with their original tags. I want just the plain text involved without
>> any tags.
>
>Try this:
>
>QString DeleteTags( const QString& a_rString )
>{
<SNIP>
>}
Is there any particular reason you don't just use a QRegExp like:
static QRegExp tagMatcher("<.+>");
tagMatcher.setMinimal(true);
return (a_rString.replace(tagMatcher, ""));
Is there some reason why this shouldn't work?
--
[ signature omitted ]
Message 4 in thread
More or less both this solution and Mariusz' solution would be fine. But
since I'm already using flex to break up the plain text, if something
like this is the required solution, I'll just modify the grammar file to
read in rich text rather than plain. But since this will be a high use
algorithm, I was interested to see if an optimised qt function was
already available.
Cheers,
Nicholas.
>Try this:
>
>QString DeleteTags( const QString& a_rString )
>{
<SNIP>
>}
Is there any particular reason you don't just use a QRegExp like:
static QRegExp tagMatcher("<.+>");
tagMatcher.setMinimal(true);
return (a_rString.replace(tagMatcher, ""));
Is there some reason why this shouldn't work?
Message 5 in thread
On Sat 16. March 2002 10:39, you wrote:
> Mariusz Lotko <mariusz.lotko@pruftechnik.com.pl> wrote:
> >On Fri 15. March 2002 06:56, you wrote:
> >> Hi,
> >> I have a QTextEdit fill withh tagged rich text. Is their any way to
> >> acquire back from the QTextEdit the text it is actually displaying? -
> >> Unfortunately, only using the 'text()' function returns that text mixed
> >> in with their original tags. I want just the plain text involved without
> >> any tags.
> >
> >Try this:
> >
> >QString DeleteTags( const QString& a_rString )
> >{
>
> <SNIP>
>
> >}
>
> Is there any particular reason you don't just use a QRegExp like:
>
> static QRegExp tagMatcher("<.+>");
> tagMatcher.setMinimal(true);
> return (a_rString.replace(tagMatcher, ""));
>
> Is there some reason why this shouldn't work?
Did I say that it won't? It was just my idea, you proposed sth else...
--
[ signature omitted ]
Message 6 in thread
Mariusz Lotko <mariusz.lotko@pruftechnik.com.pl> wrote:
>On Sat 16. March 2002 10:39, you wrote:
>> Mariusz Lotko <mariusz.lotko@pruftechnik.com.pl> wrote:
>> >On Fri 15. March 2002 06:56, you wrote:
>> static QRegExp tagMatcher("<.+>");
>> tagMatcher.setMinimal(true);
>> return (a_rString.replace(tagMatcher, ""));
>>
>> Is there some reason why this shouldn't work?
>
>Did I say that it won't?
No you didn't. No criticism intended. I was just being nervous that I
might have missed some obvious problem with my solution.
>It was just my idea, you proposed sth else...
And both of us are probably wondering why there isn't a standard
function for the purpose... :-)
--
[ signature omitted ]