Results 1 to 10 of 10

Thread: how to change QTextEdit background color ?

  1. #1
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question how to change QTextEdit background color ?

    hello,
    i am trying to change the background color so i saw the documentation and used the following code
    Qt Code:
    1. mainText->setAutoFillBackground(true);
    2. mainText->setPalette(QPalette(QColor(255, 250, 205)));
    To copy to clipboard, switch view to plain text mode 
    but the background still white.
    how can i change the background color?
    please help me.
    and thank you.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to change QTextEdit background color ?

    Qt Code:
    1. mainText->setStyleSheet("QTextEdit { background-color: rgb(255, 250, 205); }");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QTextEdit background color ?

    Quite strange, stylesheet works...but the setPalette doesnt.

    Is there some reason why setPalette doesnt work with QTextEdit ???

  4. #4
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to change QTextEdit background color ?

    style sheet works but the font is changed.
    and i want to display the text with special font.
    other thing please what is the class that "setStyleSheet" belongs?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to change QTextEdit background color ?

    Quote Originally Posted by mismael85 View Post
    other thing please what is the class that "setStyleSheet" belongs?
    Launch Qt Assistant and write "setStyleSheet" to the Index-tab.
    J-P Nurmi

  6. #6
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to change QTextEdit background color ?

    Qt 4.4's QTextEdit also has setTextBackgroundColor(const QColor & color) and setTextColor(const QColor & color).

  7. #7
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QTextEdit background color ?

    My code currently reads:

    Qt Code:
    1. QPalette p( palette() );
    2. p.setColor( QPalette::Base, c.currentColorScheme->getColorDef("dsWidgetBackground").getBackground() );
    3. setPalette( p );
    To copy to clipboard, switch view to plain text mode 

    And seems to work, but kinda ugly

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QTextEdit background color ?

    Qt 4.4's QTextEdit also has setTextBackgroundColor(const QColor & color)
    It does have, but it sets only the background of number of chars int he QTextEdit. It doesnt render the whole background of QTextEdit

  9. #9
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to change QTextEdit background color ?

    Ah, I see. Sorry about that.

  10. #10
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to change QTextEdit background color ?

    sorry, but the Qt assitante does not work with me .
    because i compiled the Qt on dirve c: from a while.
    but now i copied the Qt from c: drive to d:
    and the assitante does not work for that reason.
    and it says that the documentation file does not exist on c:, but it exists on d:.
    i will copy the Qt on c: to be able to open the assitante.
    and thank you.

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. Qt4 - QTextEdit - background color
    By impeteperry in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2009, 07:52
  4. Replies: 2
    Last Post: 9th March 2007, 23:19
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.