Results 1 to 6 of 6

Thread: Background in stockchart example

  1. #1
    Join Date
    Dec 2013
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Background in stockchart example

    Hi,

    I'm playing with the stockchart example and trying to change the background color of the plot. I'm using
    Qt Code:
    1. setCanvasBackground(QColor(Qt::red))
    To copy to clipboard, switch view to plain text mode 
    in the Plot::Plot() constructor but all this does is that it draws a border of 1px width next to the right and bottom axis. Could someone explain to me what I am doing wrong, please?

    stockchart.png

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Qt products
    Qt5
    Platforms
    Windows
    Thanked 16 Times in 15 Posts

    Default Re: Background in stockchart example

    Look into the method void Plot:opulate() and comment out the gridItem.

    Thus...

    void Plot:opulate()
    {
    GridItem *gridItem = new GridItem();
    #if 0
    gridItem->setOrientations( Qt::Horizontal );
    #endif
    gridItem->attach( this );

    ...
    }

    Becomes

    void Plot:opulate()
    {
    //GridItem *gridItem = new GridItem();
    //#if 0
    //gridItem->setOrientations( Qt::Horizontal );
    //#endif
    //gridItem->attach( this );

    ...
    }

    Of course you still need to send setCanvasBackground() to the instance of Plot.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Background in stockchart example

    Quote Originally Posted by wooosh View Post
    Could someone explain to me what I am doing wrong, please?
    You copied code from a Qwt example without trying to understand it: the red background is covered by a plot item that draws the chess board.
    Remove the grid item from your copy and you have what you want.

    Uwe

  4. #4
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Qt products
    Qt5
    Platforms
    Windows
    Thanked 16 Times in 15 Posts

    Default Re: Background in stockchart example

    A quick update...

    The suggestion to comment out the grid code forces you to live without the grid. I assume that that was ok. If it's not Then do the following:-

    In the constructor GridItem::GridItem() initialize the QPalette instance m_palette.

    f.e

    GridItem::GridItem():
    QwtPlotItem( QwtText( "Grid" ) ),
    m_orientations( Qt::Horizontal | Qt::Vertical ),
    m_gridAttributes( AutoUpdate | FillCanvas ),
    m_isXMinEnabled( false ),
    m_isYMinEnabled( false )
    {
    ...
    m_palette.setBrush(QPalette::Base, QColor(255, 0, 0));
    m_palette.setBrush(QPalette::AlternateBase , QColor(200, 0, 0));

    }

  5. #5
    Join Date
    Dec 2013
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Background in stockchart example

    Hi,

    thanks a lot for your answers.
    I did not expect the GridItem to draw the chessboard but just a grid. I thought the chessboard was some default 'no color set' background. I'm new to this.. thanks again.


    Added after 5 minutes:


    Quote Originally Posted by Cah View Post
    A quick update...

    The suggestion to comment out the grid code forces you to live without the grid. I assume that that was ok. If it's not Then do the following:-
    }
    I found this to work well for me:
    Qt Code:
    1. QwtPlotGrid *grid = new QwtPlotGrid();
    2. grid->setItemAttribute(grid->Legend, false);
    3. grid->setItemAttribute(grid->AutoScale, true);
    4. grid->setPen(QColor(Qt::gray), 0.0, Qt::PenStyle::DotLine);
    To copy to clipboard, switch view to plain text mode 
    Last edited by wooosh; 6th January 2014 at 10:34.

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

    Default Re: Background in stockchart example

    Quote Originally Posted by wooosh View Post
    grid->setItemAttribute(grid->AutoScale, true);
    This line doesn't hurt as a QwtPlotGrid has no bounding rectangle to affect the autoscaler - but enabling autoscaling for this type of grid is probably not what you want.

    Uwe

Similar Threads

  1. Replies: 4
    Last Post: 27th November 2013, 16:15
  2. Qt3 : How to set the background??
    By Kunkka in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2011, 03:07
  3. Replies: 0
    Last Post: 5th April 2011, 14:36
  4. Replies: 1
    Last Post: 25th June 2010, 19:31
  5. How to set background
    By zbliujia in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2009, 06:18

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
  •  
Qt is a trademark of The Qt Company.