Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to restore QTextEdit original background color?

[Solved] How to restore QTextEdit original background color?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 20.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hryqt
    wrote on 1 Nov 2012, 16:49 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuhamedAuda
      wrote on 1 Nov 2012, 17:09 last edited by
      #2

      @rgb(255, 255, 255)@

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hryqt
        wrote on 1 Nov 2012, 17:14 last edited by
        #3

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

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuhamedAuda
          wrote on 1 Nov 2012, 17:20 last edited by
          #4

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

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hryqt
            wrote on 1 Nov 2012, 17:22 last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuhamedAuda
              wrote on 1 Nov 2012, 17:26 last edited by
              #6

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

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hryqt
                wrote on 1 Nov 2012, 17:30 last edited by
                #7

                [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.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jake007
                  wrote on 1 Nov 2012, 17:39 last edited by
                  #8

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


                  Code is poetry

                  1 Reply Last reply
                  1
                  • H Offline
                    H Offline
                    hryqt
                    wrote on 1 Nov 2012, 17:41 last edited by
                    #9

                    [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!

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Jake007
                      wrote on 1 Nov 2012, 17:44 last edited by
                      #10

                      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


                      Code is poetry

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        hryqt
                        wrote on 1 Nov 2012, 17:50 last edited by
                        #11

                        [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)?

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MuhamedAuda
                          wrote on 2 Nov 2012, 08:40 last edited by
                          #12

                          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;;
                          

                          }
                          @

                          1 Reply Last reply
                          0

                          7/12

                          1 Nov 2012, 17:30

                          • Login

                          • Login or register to search.
                          7 out of 12
                          • First post
                            7/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved