Results 1 to 15 of 15

Thread: QwtPlotMarker and scaling

  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default 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

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  3. #3
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default 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

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default 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

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by carhun View Post
    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 View Post
    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

  7. #7
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by Uwe View Post
    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

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by carhun View Post
    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

  9. #9
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default 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
    Last edited by carhun; 5th July 2012 at 10:38.

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by carhun View Post
    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.

    Qt Code:
    1. virtual void YourMarker::drawLabel( QPainter *painter,
    2. const QRectF &canvasRect, const QPointF &pos ) const
    3. {
    4. const QSizeF labelSize = label().size( painter->font() );
    5.  
    6. const QRectF rect = labelGeometry( pos, labelSize );
    7. label().draw( painter, rect );
    8. }
    To copy to clipboard, switch view to plain text mode 

    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

  11. The following user says thank you to Uwe for this useful post:

    carhun (6th July 2012)

  12. #11
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotMarker and scaling

    Idea I understand, if it will be some question about this topic Ill ask U

    Thanks, Uwe

    carhun

  13. #12
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotMarker and scaling

    Hello, Uwe...

    I want to ask U about background of label. I do smth like this:
    Qt Code:
    1. const QSizeF labelSize = label().textSize(painter->font());
    2. const QRectF rect = labelGeometry(pos, labelSize);
    3.  
    4. painter->save();
    5.  
    6. painter->setPen(Qt::magenta);
    7. painter->setBrush(Qt::yellow);
    8.  
    9. label().draw(painter, rect);
    10.  
    11. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    I also try to do smth like this instead of painter->set...(...):
    Qt Code:
    1. label().setBackgroundBrush(Qt::yellow);
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. painter->fillRect(rect, m_labelBackgroundColor);
    To copy to clipboard, switch view to plain text mode 
    But is it good way?

    carhun
    Last edited by carhun; 10th July 2012 at 10:32.

  14. #13
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by carhun View Post
    Qt Code:
    1. label().setBackgroundBrush(Qt::yellow);
    To copy to clipboard, switch view to plain text mode 
    Your code assigns a background to a temporary copy of the label text object on the stack. Instead you have to write:

    Qt Code:
    1. QwtText lbl = label();
    2. lbl.setBackgroundBrush(Qt::yellow);
    3. setLabel( lbl );
    To copy to clipboard, switch view to plain text mode 
    Uwe

  15. #14
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by Uwe View Post
    Your code assigns a background to a temporary copy of the label text object on the stack. Instead you have to write:

    Qt Code:
    1. QwtText lbl = label();
    2. lbl.setBackgroundBrush(Qt::yellow);
    3. setLabel( lbl );
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. const_cast<MyMarker *>(this)->setLabel(text);
    To copy to clipboard, switch view to plain text mode 

    carhun
    Last edited by carhun; 10th July 2012 at 12:40.

  16. #15
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMarker and scaling

    Quote Originally Posted by carhun View Post
    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

Similar Threads

  1. QwtPlotMarker example
    By banita in forum Qwt
    Replies: 1
    Last Post: 24th May 2012, 13:19
  2. Cannot move QwtPlotMarker
    By eehmke in forum Qwt
    Replies: 1
    Last Post: 20th February 2012, 07:30
  3. QwtPlotMarker QwtPlotPicker
    By bss in forum Qwt
    Replies: 1
    Last Post: 15th June 2011, 12:55
  4. Replies: 5
    Last Post: 11th January 2011, 06:37
  5. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 21:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.