hi again,

i found QwtPlotScaleDraw::extent, is that the right method for me to use if i need the scale's height?

if it is, i guess it's returning the height in pixel coordinates (because it's returning an integer).

i still have some problems, but either i didn't unterstand a lot and my whole code is crap and wrong, or i just somehow can't find my mistakes ... i'd really appreciate everyone who would take a look at my code below. thanks in advance!

so, as i said, i have a class derived from QwtPlot and another one derived from QwtPlotCurve.

a third class is derived from QwtScaleDraw to provide easy access to some options like the label's font and the tick's and backbone's color.

in my scale draw, i implemented the extent method like this:

int MyScaleDraw::extent()

{

// m_labelsFont: font for labels - didn't expect this, huh? ;-)

}

int MyScaleDraw::extent()
{
// m_labelsFont: font for labels - didn't expect this, huh? ;-)
return QwtScaleDraw::extent( QPen(), m_labelsFont );
}

*To copy to clipboard, switch view to plain text mode *

in my plot class, i've got the addCurve method:

void MyPlot::addCurve( MyCurve *p_curve )

{

if( p_curve )

{

setAxisScale( xBottom, 0, 5, 1 ); // just for testing purposes

double scaleHeight = 0; // height of a scale item

p_curve->attach( this );

if( m_curves.count() > 0 ) // m_curves: QMap< MyCurve*, QwtScaleDraw* >

{

s->setScaleDraw( m_xScaleDraw );

s->attach( this );

m_curves.insert( p_curve, s );

// i'm not sure about the following:

// ( m_xScaleDraw: MyScaleDraw for xBottom scales)

if( m_xScaleDraw )

scaleHeight = canvasMap( yLeft ).invTransform(

m_xScaleDraw->extent() );

}

else

m_curves.insert( p_curve, NULL );

double curveHeight = ( 100 - ((m_curves.count() - 1)*scaleHeight))

/ (m_curves.count() );

= m_curves.begin();

int i = 0;

while( it != m_curves.end() )

{

if( it.key() )

{

// MyCurve has 2 new elements:

// height => height of the blocks

// yPos => position (top border) on y-axis

it.key()->setHeight( curveHeight );

it.key()->setYPos( ( (i + 1) * curveHeight )

+ ( i * scaleHeight ) );

}

if( it.value() )

it.value()->setPosition( it.key()->yPos()

- it.key()->height() );

it++;

i++;

}

replot();

}

}

void MyPlot::addCurve( MyCurve *p_curve )
{
if( p_curve )
{
setAxisScale( xBottom, 0, 5, 1 ); // just for testing purposes
double scaleHeight = 0; // height of a scale item
p_curve->attach( this );
if( m_curves.count() > 0 ) // m_curves: QMap< MyCurve*, QwtScaleDraw* >
{
QwtPlotScaleItem *s = new QwtPlotScaleItem;
s->setScaleDraw( m_xScaleDraw );
s->attach( this );
m_curves.insert( p_curve, s );
// i'm not sure about the following:
// ( m_xScaleDraw: MyScaleDraw for xBottom scales)
if( m_xScaleDraw )
scaleHeight = canvasMap( yLeft ).invTransform(
m_xScaleDraw->extent() );
}
else
m_curves.insert( p_curve, NULL );
double curveHeight = ( 100 - ((m_curves.count() - 1)*scaleHeight))
/ (m_curves.count() );
QMap< MyCurve*, QwtPlotScaleItem* >::iterator it
= m_curves.begin();
int i = 0;
while( it != m_curves.end() )
{
if( it.key() )
{
// MyCurve has 2 new elements:
// height => height of the blocks
// yPos => position (top border) on y-axis
it.key()->setHeight( curveHeight );
it.key()->setYPos( ( (i + 1) * curveHeight )
+ ( i * scaleHeight ) );
}
if( it.value() )
it.value()->setPosition( it.key()->yPos()
- it.key()->height() );
it++;
i++;
}
replot();
}
}

*To copy to clipboard, switch view to plain text mode *

i also tested the scaleHeight values with a message box and it seems that the scaleHeight is calculated wrongly, but i just don't know why, i tried it for so long and maybe i just need a break from this project ... but i have to get this done.

as i said, anyone willing to help here is appreciated, many thanks in advance!

// edit: added screenshots of how it looks now after adding 2 curves to the plot widget via addCurve

sincerely,

julian

## Bookmarks