Results 1 to 5 of 5

Thread: Background color

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Background color

    Hi,

    I want to change the background color of a QwtPlot. The method "setCanvasBackground" changes only the background color of the canvas. How can I change the color "under" the scales and the labels (this is normally gray)?

    I tried the following snippet with no effect...

    Qt Code:
    1. QPalette p = plot->palette();
    2. p.setColor(QPalette::Window, background);
    3. plot->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    if I remove "plot->" in the snippet, it works for my whole widget (including toolbar and statusbar). How can I change the color only in QwtPlot widget?

    thanks!
    Felix

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Background color

    Qt Code:
    1. plot->setAutoFillBackground( true );
    2. QPalette p = plot->palette();
    3. p.setColor(QPalette::Window, background);
    4. plot->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    FelixB (28th January 2011)

  4. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Background color

    thank you!

  5. #4
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Background color

    That was not helpping to make entire plot (including label background) white. Following code helpped me. But still I am getting a shadow line at left and top. Is there a way to get rid of that also?

    setCanvasBackground(QColor(Qt::white));
    setStyleSheet("background-color:white;");

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Background color

    Qt Code:
    1. plot->setAutoFillBackground( true );
    2. plot->setPalette( Qt::white );
    3. plot->setCanvasBackground( Qt::white );
    4.  
    5. QwtPlotCanvas *canvas = dynamic_cast<QwtPlotCanvas *>( plot->canvas() );
    6. canvas->setFrameStyle( QFrame::NoFrame );
    To copy to clipboard, switch view to plain text mode 
    Better don't use style sheets for silly operations like this one. In rare situations they might have a negative impact on the performance ( full repaints instead of partial updates ) - and of course they are conflicting with the concept of palettes.

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    mqt (25th June 2013)

Similar Threads

  1. textEdit background color
    By briang in forum Newbie
    Replies: 3
    Last Post: 5th November 2009, 17:24
  2. Replies: 2
    Last Post: 29th September 2009, 07:40
  3. Qt4 - QTextEdit - background color
    By impeteperry in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2009, 07:52
  4. background color of menu bar
    By sabeesh in forum Qt Programming
    Replies: 6
    Last Post: 24th July 2007, 12:48
  5. background color of a MainWindow
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2007, 09:27

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.