[Qt-interest] QTextEdit line color
Girish Ramakrishnan
girish at forwardbias.in
Wed Feb 11 08:00:00 CET 2009
Setting foreground does not work with block format. Use the char format
instead. Something like,
QTextCharFormat format;
format.setForeground(Qt::green);
tc.select(QTextCursor::BlockUnderCursor);
tc.mergeCharFormat(format);
Girish
RZ wrote:
> Answering myself and raising another question:
>
> QTextCursor tc(m_TextBlock);
> QTextBlockFormat blockFormat = m_TextBlock.blockFormat();
> blockFormat.setForeground(Qt::green); <-- this does not work
> blockFormat.setBackground(Qt::red); <-- this works
> tc.setBlockFormat(blockFormat);
>
>> Hi all,
>>
>> I got a QTextEdit where the user can insert several lines; each line
>> is a kind of "command". These commands get processed one after the
>> other. What i want to achieve is that each line changes its color
>> after "execution".
>> First intent was to use QSyntaxHighlighter - but this works on the
>> text of each line. Not usable for me as the text doesn't change after
>> execution.
>> My next idea was to iterate over all the QTextBlock's
>> (textEdit->document().begin() and callin next()). For each block I can
>> get the QTextBlockFormat and can change the foreground of the
>> QTextBlockFormat via setForeground(). _But_ there is no way to set a
>> QTextBlockFormat to the QTextBlock.
>>
>> So I'd appreciate any help.
>>
>> Thx,
>>
>> RZ
More information about the Qt-interest-old
mailing list