Hello,
I have some difficulty with a problem which seem simple (at beginning).
I created a console class (for logging) which inherits from QTextEdit. I have some Qt property for text color (one for each type of message). This property could be initialize by Qss.

In the function where I append the text, I want to save the current text color, modify it, and restore it (I really need this feature).

See the code below (that doesn't work):
Qt Code:
  1. // There, the color is invalid because I didn't defined it in Qss for
  2. // my class (I want to not defined in certain case to manage
  3. // default style without qss.).
  4. color = textcolor();
  5. // I change the color and display new text
  6. settextcolor(myNewColor);
  7. append(strText);
  8. // But code below doesn't restore the previous color
  9. // (I Think it's because the color is Invalid)
  10. settextcolor(color);
To copy to clipboard, switch view to plain text mode 

I have tried these too (but doesn't work...) :
Qt Code:
  1. // Try to save context
  2. QTextCharFormat oFormat = currentCharFormat();
  3.  
  4. setTextColor(oColor);
  5. append(strText);
  6.  
  7. // But, the code below doesn't work.
  8. setCurrentCharFormat(oFormat);
To copy to clipboard, switch view to plain text mode 

I also try with QPalette (palette, setpalette()), but it doesn't work too.

I have search for the same mechanism as QPainter with save() and restore(), but I didn't thind any solution.

Is someone known how to save text color, backgound color and font in a context and restore them after modification ?
The problem in my case, is that If the user (in Qss) doesn't set a color for my property, Qt initialize it with invalid color and take the parent in Qss (but it do it in intern, textcolor() return invalid color). And I didn't found solution to restore this default color.

I think there iis a solution, but I didn't find it.
I hope someone could help me.