I have found in the source code of Qwt this:
const QwtText &QwtAbstractScaleDraw
::tickLabel( const QFont &font,
double value
) const {
QMap<double, QwtText>::const_iterator it = d_data->labelCache.find( value );
if ( it == d_data->labelCache.end() )
{
lbl.setRenderFlags( 0 );
lbl.
setLayoutAttribute( QwtText::MinimumLayout );
( void )lbl.textSize( font ); // initialize the internal cache
it = d_data->labelCache.insert( value, lbl );
}
return ( *it );
}
const QwtText &QwtAbstractScaleDraw::tickLabel(
const QFont &font, double value ) const
{
QMap<double, QwtText>::const_iterator it = d_data->labelCache.find( value );
if ( it == d_data->labelCache.end() )
{
QwtText lbl = label( value );
lbl.setRenderFlags( 0 );
lbl.setLayoutAttribute( QwtText::MinimumLayout );
( void )lbl.textSize( font ); // initialize the internal cache
it = d_data->labelCache.insert( value, lbl );
}
return ( *it );
}
To copy to clipboard, switch view to plain text mode
It is the method who, I guess, generate the QwtText Label.
It seems that the line 8 set the render flags to '0'. May be it why changing the renderFlags of the label don't change the alignement of the label under the tick.
What do you think ?
Added after 10 minutes:
That's it
Instead of override the method
label(double value)
label(double value)
To copy to clipboard, switch view to plain text mode
.
I have to override the drawlable method:
void drawLabel
( QPainter *painter,
double value
) const override
{
QwtText lbl
= tickLabel
( painter
->font
(), value
);
if ( lbl.isEmpty() )
return;
lbl.setRenderFlags(Qt::AlignCenter); //<---- add this line in the subclass
QPointF pos
= labelPosition
( value
);
QSizeF labelSize
= lbl.
textSize( painter
->font
() );
const QTransform transform = labelTransformation( pos, labelSize );
painter->save();
painter->setWorldTransform( transform, true );
lbl.
draw ( painter,
QRect( QPoint( 0,
0 ), labelSize.
toSize() ) );
painter->restore();
}
void drawLabel( QPainter *painter, double value ) const override
{
QwtText lbl = tickLabel( painter->font(), value );
if ( lbl.isEmpty() )
return;
lbl.setRenderFlags(Qt::AlignCenter); //<---- add this line in the subclass
QPointF pos = labelPosition( value );
QSizeF labelSize = lbl.textSize( painter->font() );
const QTransform transform = labelTransformation( pos, labelSize );
painter->save();
painter->setWorldTransform( transform, true );
lbl.draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
painter->restore();
}
To copy to clipboard, switch view to plain text mode
And after the label is really center !
the setRenderFlags do not the job !!!
Bookmarks