+ Reply to Thread
Results 1 to 10 of 10

Thread: Qt4 - QTextEdit - background color

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Qt4 - QTextEdit - background color

    Hi, I have several QTextEdit widgets. I have no Idea on how to set the background colors. In Qt3 I used
    Qt Code:
    1. teErrorMessages->setPaletteBackgroundColor( QColor( 240, 240, 255 ) );
    To copy to clipboard, switch view to plain text mode 
    I have looked at designer, Qt3 to Qt4 docs. the Qt4 demos, and am still at a loss.

    Any help would be most appreciated.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 79 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 - QTextEdit - background color

    setBackgroundRole(QPalette::ColorRole role) in QWidget

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

    Default Re: Qt4 - QTextEdit - background color

    Text entry widgets usually use QPalette::Base as the background color.
    Qt Code:
    1. QPalette p = textEdit->palette();
    2. p.setColor(QPalette::Base, QColor(240, 240, 255));
    3. textEdit->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    macias (24th June 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 - QTextEdit - background color

    Thanks for the prompt reply, but still have a problem.
    I am using designer.so entered
    Qt Code:
    1. QPalette p = ui.helpBox->palette();
    2. p.setColor(QPalette::Base, QColor(240, 240, 255));
    3. ui.helpBox->setPalette(p);.
    To copy to clipboard, switch view to plain text mode 
    when I compiled I got
    edpform.cpp:167: error: expected primary-expression before ‘.’ token
    Line 167 is the ui.helpBox->setPalette(p);
    so I went back in designer and opened the "palette" in the Property Editor for the helpBox ( QTextEdit Widget ). I was able to change the color there, but I want to change the background color from within the program.

    thanks

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 973 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 - QTextEdit - background color

    Quote Originally Posted by impeteperry
    ui.helpBox->setPalette(p);.
    There's a dot after semicolon --- remove it.

  7. #6
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 - QTextEdit - background color

    boy you have better eyes then I do ( 80 years old ) thanks a million

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

    Default Re: Qt4 - QTextEdit - background color

    Quote Originally Posted by impeteperry
    boy you have better eyes then I do ( 80 years old ) thanks a million
    You meant 80 years young dud...

  9. The following user says thank you to elcuco for this useful post:

    impeteperry (14th May 2006)

  10. #8
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 - QTextEdit - background color

    Ain't ready to quit yet. Maybe I'll get it right next year.
    Thanks to you and all your buddies @ Qt Centre.

  11. #9
    Join Date
    Jan 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 - QTextEdit - background color

    Quote Originally Posted by jpn View Post
    Text entry widgets usually use QPalette::Base as the background color.
    Qt Code:
    1. QPalette p = textEdit->palette();
    2. p.setColor(QPalette::Base, QColor(240, 240, 255));
    3. textEdit->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    How can i change the foreground (text) color of the QLineEdit ?

    p.setColor(QPalette.WindowText, Qt::red)
    ...

    doesn't work....

    Greetings,
    Nando

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

    Default Re: Qt4 - QTextEdit - background color

    Try using QPalette::Text:
    The foreground color used with Base. This is usually the same as the WindowText, in which case it must provide good contrast with Window and Base.
    J-P Nurmi

+ Reply to Thread

Similar Threads

  1. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 15:02
  2. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  3. QTextEdit & background colors
    By marziac in forum Qt Programming
    Replies: 4
    Last Post: 24th August 2007, 12:52
  4. Replies: 2
    Last Post: 9th March 2007, 23:19
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36

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