[Qt-interest] Different Text background color in QTextEdit
rajasekharan
websweetweb at gmail.com
Wed Aug 19 21:04:14 CEST 2009
Hari,
This was in the code editor example. This is the method that highlights
the current line in which the cursor is. You have to sub class QTextEdit
and add this method:
void CodeEditor::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (!isReadOnly()) {
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
I guess the if (!isReadOnly()) statement can be removed for your case.
Kind Regards,
Raj Sekharan
Hari Sundar wrote:
> Hi,
>
> I am trying to use QTextEdit in the read only mode to display
> formatted log messages for my program. For this purpose, I wish to add
> different lines formatted differently and with different background
> colors based on the type of message.
>
> I tried to do this initially using HTML and stylesheet, but it appears
> that CSS stylesheets are not fully supported. Specifically I was
> unable to get background colors to work.
>
> So, I switched to using QTextCharFormat / QTextFrameFormat etc ... to
> format my text, but am unable to set background color even with this.
>
> Is it possible ? What am I missing ? Alternatively is there any other
> widget better suited for this task ?
>
> thanks,
> Hari
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090820/8b36a82f/attachment.html
More information about the Qt-interest-old
mailing list