QwtPlotMarker and scaling
Hello!
For example I have n markers in QwtPlot that are located horizontally...
And I want that this markers will be locate at coordinates: (x + 1*width(marker_1), Y) , (x + i * width(marker_i), Y) .... , (x + n *width(marker_n), Y). Where is x = 50 and Y = 100 - for example....
So I have some questions:
1. How I can get width and height of some marker with some text: "text + number of marker"?
2. When I will do scaling I'll have some space between markers. How I can take into account or how I can compute this space? I want that all my markers always paint without any spacing....
I hope U can give me some usefull advise.
Yours,
carhun
Re: QwtPlotMarker and scaling
This is probably a different type of plot item, but no marker ( in the terminology of Qwt ).
What type of information do you want to display ?
Uwe
Re: QwtPlotMarker and scaling
Hello, Uwe!
I want to display value of y that corresponds to pos.x(). And what i want to display must have some unique ( for all my "markers") background color and for example white color of pen ( font )...
So I have function that return me y = f(x) , where x = pos.x() and I want to display this with the condition that was described above...
Thanks
Youes,
carhun
Re: QwtPlotMarker and scaling
All classes of the Qwt plot framework use QwtText instead of QString.
Beside the option of using different text engines ( pseudo-HTML, MathML ) each instance of QwtText has its individual attributes: font, pen and an optional background are among them.
But your second posting doesn't explain why you need the layout code of the first posting ?
Uwe
Re: QwtPlotMarker and scaling
Yes, QwtText has it individual attributes that I need, but I cant say to QwtText - draw at (x,y)... For QwtPlotMarker I can do it with help of function someMarker->setValue(x, y)... So I need some class where I can write my QwtText and say where draw/write this text...
About your question I didnt understand it completely, but try to explain one more why I need to do like I write in first post:
I have N functions/graphics: f1(x) , f2(x), ..., fN(x). Then I have tracker that tell me pos.x() of mouse in the QwtPlot. And I want to display text that indicate value of fN(pos.x()), where is N = 1, ... N; And there is may be situation when two or more graphics will have same values of y = f1(x) = f2(x), so i need to display at point (pos.x(), y) - value of first function and at (pos.x() + width(QwtText/orsmth like this), y) - value of second function... I only want that they go always straight without any empty space between them...
I hope this explanation is more clear...
Yours,
carhun
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
carhun
Yes, QwtText has it individual attributes that I need, but I cant say to QwtText - draw at (x,y)... For QwtPlotMarker I can do it with help of function someMarker->setValue(x, y)...
Sure you can: QwtPlotMarker::setLabel( const QwtText& );
Quote:
Originally Posted by
carhun
About your question I didnt understand it completely, but try to explain one more why I need to do like I write in first post: ...
So the code snippet was about how to avoid that marker labels overlap ?
Uwe
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
Uwe
So the code snippet was about how to avoid that marker labels overlap ?
In general situation - yes, how to avoid overlapping of the marker labels
Yours,
carhun
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
carhun
In general situation - yes, how to avoid overlapping of the marker labels
First of all you need to define your algorithm for a conflict resolution - Qwt doesn't offer one, basically because I don't know a satisfying general solution.
Then I can help with how to implement it with Qwt.
Uwe
Re: QwtPlotMarker and scaling
I thought that algorithm will be next ( if I correctly understand about what conflicts you are talking ):
I have for example three point where I want to display my markers:
(2, 5), (4,5), (10,5).
So if we have the width of marker, we can check:
So I have interval (2, 2 + width) and I check with other X's of markers (4,10, etc ) and If some X's is in interval (2, 2 + width), so we have overlapping and i want to resolve this conflict in next for example way: the X value of second point [(4,5)] we set to 2 + width + 1...
Or I have some massive that contains value of Y and vector of X's that correspond to value Y:
In example above: 5 -> 2, 4, 10....
and then we need to display our markers in points: (2,5) (2+1*width, 5) (2 + 2*width, 5)
And so on for all markers...
Mb U have better solution?
Yours,
carhun
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
carhun
I have for example three point where I want to display my markers:
(2, 5), (4,5), (10,5).
The plot coordinates of the markers are of no importance - what you need are widget coordinates, f.e what you get when overloading QwtPlotMarker::drawLabel.
Code:
virtual void YourMarker
::drawLabel( QPainter *painter,
{
const QSizeF labelSize
= label
().
size( painter
->font
() );
const QRectF rect
= labelGeometry
( pos, labelSize
);
label().draw( painter, rect );
}
Of course the problem now is how to implement YourMarker::labelGeometry(). A conflict resolution ( = avoid overlapping of marker labels ) needs to know position and size in widget coordinates of all markers.
Uwe
Re: QwtPlotMarker and scaling
Idea I understand, if it will be some question about this topic Ill ask U:D
Thanks, Uwe
carhun
Re: QwtPlotMarker and scaling
Hello, Uwe...
I want to ask U about background of label. I do smth like this:
Code:
const QSizeF labelSize
= label
().
textSize(painter
->font
());
const QRectF rect
= labelGeometry
(pos, labelSize
);
painter->save();
painter->setPen(Qt::magenta);
painter->setBrush(Qt::yellow);
label().draw(painter, rect);
painter->restore();
I also try to do smth like this instead of painter->set...(...):
Code:
label().setBackgroundBrush(Qt::yellow);
But text is shown correctly ( color = magenta ), but background - no ( background is white, not as I want f.e. yellow).
Can U tell me why? What I am doing wrong?
If i do smth like this, it is ok:
Code:
painter->fillRect(rect, m_labelBackgroundColor);
But is it good way?
carhun
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
carhun
Code:
label().setBackgroundBrush(Qt::yellow);
Your code assigns a background to a temporary copy of the label text object on the stack. Instead you have to write:
Code:
lbl.setBackgroundBrush(Qt::yellow);
setLabel( lbl );
Uwe
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
Uwe
Your code assigns a background to a temporary copy of the label text object on the stack. Instead you have to write:
Code:
lbl.setBackgroundBrush(Qt::yellow);
setLabel( lbl );
Uwe
It didn't help, results are same...
And I coudnt this do because drawLabel is const method...
Thanks, its work, but i need to do const_cast to do this:
Code:
const_cast<MyMarker *>(this)->setLabel(text);
carhun
Re: QwtPlotMarker and scaling
Quote:
Originally Posted by
carhun
And I coudnt this do because drawLabel is const method...
Of course this code is not intended to be inside of drawLabel - assign the background once not inside somewhere called below replot !
Uwe