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):
// There, the color is invalid because I didn't defined it in Qss for
// my class (I want to not defined in certain case to manage
// default style without qss.).
color = textcolor();
// I change the color and display new text
settextcolor(myNewColor);
append(strText);
// But code below doesn't restore the previous color
// (I Think it's because the color is Invalid)
settextcolor(color);
// There, the color is invalid because I didn't defined it in Qss for
// my class (I want to not defined in certain case to manage
// default style without qss.).
color = textcolor();
// I change the color and display new text
settextcolor(myNewColor);
append(strText);
// But code below doesn't restore the previous color
// (I Think it's because the color is Invalid)
settextcolor(color);
To copy to clipboard, switch view to plain text mode
I have tried these too (but doesn't work...) :
// Try to save context
setTextColor(oColor);
append(strText);
// But, the code below doesn't work.
setCurrentCharFormat(oFormat);
// Try to save context
QTextCharFormat oFormat = currentCharFormat();
setTextColor(oColor);
append(strText);
// But, the code below doesn't work.
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.
Bookmarks