[Solved] How to restore QTextEdit original background color?



  • Dear all,

    I'm sorry if this is a silly question, but I have been searching everywhere.

    What's the original background color of QTextEdit?

    I change QTextEdit background color when the user click on it, and I want to restore it when it's not in edit mode anymore.

    Do I need to know its original background color? or is there another way to achieve this (restoring original background color)?

    Thanks a lot.



  • @rgb(255, 255, 255)@



  • [quote author="MuhamedAuda" date="1351789762"]@rgb(255, 255, 255)@[/quote]

    No, it's not white. It's like light greyish.



  • or u can set it in code like this:
    @ this->ui->textEdit->setStyleSheet("background-color: rgb(255, 255, 255)");
    @



  • [quote author="MuhamedAuda" date="1351790408"]or u can set it in code like this: @ this->ui->textEdit->setStyleSheet("background-color: rgb(255, 255, 255)"); @[/quote]

    That is not my point. What you refer to as rgb(255,255,255) will give "White" color.
    But my original QTextEdit color is not white.



  • i think the default background color OS color base ...



  • [quote author="MuhamedAuda" date="1351790782"]i think the default background color OS color base ...[/quote]

    Yes, I agree. It's OS dependent.

    That's why I want to know how to restore it back to its original color after I change it?

    I thought I need to know the original color in order to restore it. Or maybe there's another way to do this.



  • If you want default OS style of an widget, just set style to empty string:
    @setStyleSheet("");@



  • [quote author="Jake007" date="1351791547"]If you want default OS style of an widget, just set style to empty string: @setStyleSheet("");@ [/quote]

    Ah, yes, it works! Thanks a lot!



  • I'm glad I could help :) .
    Please mark topic as solved ( edit your first post and add [Solved] in front of the title).

    Regards,
    Jake



  • [quote author="Jake007" date="1351791872"]I'm glad I could help :) . Please mark topic as solved ( edit your first post and add [Solved] in front of the title). Regards, Jake[/quote]

    Done! Thanks, Jake :)

    Btw, do you happen to know the solution for my other question? (QTextEdit cursor)?



  • yes it work full example
    @#include <QtGui/QApplication>
    #include <QWidget>
    #include <QTextEdit>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QWidget w;

    QTextEdit *txtEdit = new QTextEdit(&w);
    // to change backgournd color
    txtEdit->setStyleSheet("background-color: rgb(255, 1, 255)"); 
    // to reset it to default color ...
    txtEdit->setStyleSheet("");
    w.show();    
    return a.exec&#40;&#41;;
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.