PDA

View Full Version : PlotPicker: TrackerText Position



FelixB
13th December 2010, 13:40
Hi,

I'd like to change the position of the trackerText from Top/Right to Bottom/Left. Is there a possibility to do that? I already have my own subclass where I set the trackerText. I tried to override "drawTracker(QPainter*)" and "trackerRect(const QFont&)", but that did not work. The position did not change - instead it disappeared sometimes. I think the problem is, that "trackerRect()" is not declared virtual...

is there a better way than copying almost each line from qwt_picker.h?

thanks!
Felix

Uwe
14th December 2010, 07:28
Overloading drawTracker is the correct idea. Start with this code:


void YourPicker::drawTracker( QPainter *painter ) const
{
const QRect textRect = trackerRect( painter->font() );
if ( !textRect.isEmpty() )
{
QwtText label = trackerText( trackerPosition() );
if ( !label.isEmpty() )
label.draw( painter, textRect );
}
}

Uwe

PS: QwtPicker::trackerRect is changed to virtual in SVN trunk

FelixB
14th December 2010, 08:27
PS: QwtPicker::trackerRect is changed to virtual in SVN trunk

thank you! when I have time, I'll convert my application to Qwt 6 :)
I tried to move the resulting rect - but now the Label is disappeared completely.

void YourPicker::drawTracker( QPainter *painter ) const
{
QRect textRect = trackerRect( painter->font() ); // removed "const"
textRect.moveTopLeft(QPoint(100,100)); // new line
if ( !textRect.isEmpty() )
{
QwtText label = trackerText( trackerPosition() );
if ( !label.isEmpty() )
label.draw( painter, textRect );
}
}

The reason I'm doing this is: In my plot I have a scrollzoomer with scrollbars set to "AlwaysOn" and "AttachedToScales" (they are attached to xTop and yRight). When I move the mouse close to one of the scrollbars, the trackertext is painted on the scrollbar (this does not happen if scrollbar is "AsNeeded" - in this case the trackertext is painted "under" the scrollbar, so it is not visible). When you now move the mouse parallel to the scrollbar, parts of the old trackertext label remain where they were. unfortunately I can't make a screenshot - when I press a button, the scrollbar gets repainted.