View Full Version : Background in stockchart example
wooosh
5th January 2014, 20:23
Hi,
I'm playing with the stockchart example and trying to change the background color of the plot. I'm using
setCanvasBackground(QColor(Qt::red)) 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?
9908
Cah
6th January 2014, 08:35
Look into the method void Plot::populate() and comment out the gridItem.
Thus...
void Plot::populate()
{
GridItem *gridItem = new GridItem();
#if 0
gridItem->setOrientations( Qt::Horizontal );
#endif
gridItem->attach( this );
...
}
Becomes
void Plot::populate()
{
//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.
Uwe
6th January 2014, 08:49
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
Cah
6th January 2014, 09:09
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));
}
wooosh
6th January 2014, 09:34
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:
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:
QwtPlotGrid *grid = new QwtPlotGrid();
grid->setItemAttribute(grid->Legend, false);
grid->setItemAttribute(grid->AutoScale, true);
grid->setPen(QColor(Qt::gray), 0.0, Qt::PenStyle::DotLine);
Uwe
7th January 2014, 06:38
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.