×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Question Restore default text color in QTextEdit (with Qss style)

    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):
    Code:
    // 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);
    I have tried these too (but doesn't work...) :
    Code:
    // Try to save context
    QTextCharFormat oFormat = currentCharFormat();
    
    setTextColor(oColor);
    append(strText);
    
    // But, the code below doesn't work.
    setCurrentCharFormat(oFormat);
    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.

    Please, help me. I'm sure there is a solution, but I didn't find it.

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Restore default text color in QTextEdit (with Qss style)

    Did I understood it correctly, that you want to append text to the QTextEdit with the same formatting and colour as already entered text in the widget has?

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2

    Re: Restore default text color in QTextEdit (with Qss style)

    I want to append text sometimes with a specific color (as example for warning message in red) or sometimes with the QTextEdit default color.

    Take an example. I want to display a standard message, a warning one and a other standard message.
    This is the code I execute :
    Code:
    append("First standard message with no specific color");
    ...
    settextcolor(m_WarningTextColor);
    append("A warning message with a specific color");
    ...
    append("A second message with no specific color");
    If I execute the code above, the last text 'A second message with no specific color' has the same color has warning message.

    So I've try this :
    Code:
    OldTextColor = textcolor()
    append("First standard message with no specific color");
    ...
    settextcolor(m_WarningTextColor);
    append("A warning message with a specific color");
    ...
    settextcolor(OldTextColor);
    append("A second message with no specific color");
    If I execute the code above, the last text 'A second message with no specific color' is write in black (because OldTextColor retrieve with textcolor() is an invalid color).

    And I have the same problem for the backgroundtextcolor.

    I hope I was more clear.

    So, the question is : How get the default text and background color on a QTextEdit ?

Similar Threads

  1. Default text in CAknMultiLineDataQueryDialo g
    By beli in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-08-05, 13:35
  2. Default text for CEikEdwin
    By rkuppala in forum Symbian User Interface
    Replies: 6
    Last Post: 2005-12-08, 07:02
  3. Default text color in CEikRichTextEditor
    By malep1 in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-03-02, 13:54
  4. change default style in link
    By m.scrima in forum Browsing and Mark-ups
    Replies: 6
    Last Post: 2003-11-17, 11:33
  5. ListBox default text
    By datho in forum Symbian User Interface
    Replies: 4
    Last Post: 2003-07-15, 18:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×