September 30, 2010

darkdescendant darkdescenda..
Lab Rat
4 posts

Text selections is causing custom formatting to be overwritten

 

I am using a QTextEdit widget with a QSyntaxHighligher attached to do syntax highlighting. This is a great solution but I have run into an issue I can’t seem to find any info on.

It appears that text selection/highlighting in QTextEdit causes the formatting for the selected text to be replaced with the selection foreground and background colors. As soon as you remove the selection the formatting returns but while selected all my formatting is gone.

Is there any way to make selection highlighting to respect the current format? Somehow change the highlighting format specifically so it blends with the text formatting and not replaces it?

Thanx,
joe

4 replies

September 30, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts
darkdescendant wrote:
Is there any way to make selection highlighting to respect the current format? Somehow change the highlighting format specifically so it blends with the text formatting and not replaces it?

When you say current format, are you talking about italics and bold? Even if you use the QSyntaxHighlighter they are still retained. You can see the richtext/syntax highlighter demo that ships with Qt …

or are you talking about some other format?

September 30, 2010

darkdescendant darkdescenda..
Lab Rat
4 posts

What I mean is that things like background and foreground text colors are being replaced by the highilight colors. Bold and italic are still there but those are not the only two text properties that carry information in my app.

October 1, 2010

VC15 VC15
Lab Rat
25 posts

I tried selecting a highlighted text in Eclipse and PSPad. It also loses its colors. Maybe it is a common behavior.
Maybe there is a performance reason – replacing a color is easier than blending with it.
Excuse that my post actually doesn’t help with the problem.

October 1, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

how about using these style attributes in a stylesheet?

selection-color and selection-background-color

would that solve your problem. I’m able to set my choice of colors here …

 
  ‹‹ QToolButton stylesheet      Extending SWT with Qt widgets ››

You must log in to post a reply. Not a member yet? Register here!