Results 1 to 8 of 8

Thread: QwtPlotPicker questions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: QwtPlotPicker questions

    1) I added a QwtPlotPicker, and it seems to work fine. But how can I get the picker selection (i.e. a rectangle or ellipsoid) to stay on the plot?
    You have to implement a new type of QwtPlotItem, that displays your rectangle/ellipsoid. In YourPlotItem::draw use QwtPainter::drawRect/drawEllipse instead of QPainter::drawRect/Ellipse if you want to use QwtPlot::print.
    2) how can I iterate through the points on my image to highlight those that are inside the picker selection?
    Qt Code:
    1. QRect QwtPlotItem::transform(const QwtScaleMap &xMap,
    2. const QwtScaleMap &yMap, const QwtDoubleRect& rect) const
    To copy to clipboard, switch view to plain text mode 


    Uwe

  2. #2
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotPicker questions

    Quote Originally Posted by Uwe View Post
    You have to implement a new type of QwtPlotItem, that displays your rectangle/ellipsoid. In YourPlotItem::draw use QwtPainter::drawRect/drawEllipse instead of QPainter::drawRect/Ellipse if you want to use QwtPlot:rint.
    I tried the following

    Qt Code:
    1. class SelectionPlotItem : public QwtPlotItem
    2. {
    3. public:
    4. SelectionPlotItem(const QwtText &title=QwtText());
    5. virtual void draw (QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const;
    6.  
    7.  
    8. private:
    9. };
    To copy to clipboard, switch view to plain text mode 
    and override the draw() method
    Qt Code:
    1. void SelectionPlotItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const
    2. {
    3. painter->save();
    4. QwtPolygon poly = QwtPolygon(canvasRect);
    5. painter->setPen(QPen(QColor(Qt::blue)));
    6.  
    7. QwtPainter::drawPolygon(painter, poly);
    8. painter->restore();
    9. }
    To copy to clipboard, switch view to plain text mode 
    but it doesn't seem to do anything
    Qt Code:
    1. QRect QwtPlotItem::transform(const QwtScaleMap &xMap,
    2. const QwtScaleMap &yMap, const QwtDoubleRect& rect) const
    To copy to clipboard, switch view to plain text mode 


    Uwe
    Re/ my 2nd question - but how am I going to iterate through the points on my image to select those point inside the polygon selection?

    Perhaps my renderImage is defined incorrectly?

    Qt Code:
    1. QImage OverlayImagePlot::renderImage(const QwtScaleMap &xMap,
    2. const QwtScaleMap &yMap, const QwtDoubleRect &area) const
    3. {
    4.  
    5.  
    6. return QImage(_filename);
    7. }
    To copy to clipboard, switch view to plain text mode 
    my custom class was defined as:
    class OverlayImagePlot : public QwtPlotRasterItem
    {
    public:
    OverlayImagePlot();
    OverlayImagePlot(const QwtText &title);
    OverlayImagePlot(const QString &title);

    virtual ~OverlayImagePlot();
    void setArea(QRect area) {_area = area;}
    void setFilename(QString filename);
    void setPlot(QwtPlot *plot);

    protected:
    virtual QImage renderImage(const QwtScaleMap &xMap,
    const QwtScaleMap &yMap, const QwtDoubleRect &area) const;

    private:
    QwtPlot *_plot;
    QRect _area;
    QString _filename;
    };

  3. #3
    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: QwtPlotPicker questions

    Quote Originally Posted by ttvo View Post
    I tried the following
    A selection item without a selection ???

    Qt Code:
    1. class SelectionPlotItem : public QwtPlotItem
    2. {
    3. public:
    4. SelectionPlotItem(const QwtText &title=QwtText());
    5.  
    6. void setSelection(const QwtDoubleRect &);
    7. virtual void draw (QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const;
    8.  
    9.  
    10. private:
    11. QwtDoubleRect m_selection;
    12. };
    13.  
    14. void SelectionPlotItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const
    15. {
    16. if ( !m_selection.isEmpty() )
    17. {
    18. const QRect r = transform(xMap, yMap, m_selection);
    19. painter->setPen(...);
    20. painter->setBrush(...);
    21. QwtPainter::drawRect(painter, r);
    22. }
    To copy to clipboard, switch view to plain text mode 

    Instead of the rectangle you could paint all without the rectangle with a semi-transparent ( small alpha value ) white brush. "Lowlighting" the non-selected parts has a similar effect as highlighting the selected area.
    Re/ my 2nd question - but how am I going to iterate through the points on my image to select those point inside the polygon selection?
    Look at the implementation of QwtPlotSpectrogram::renderImage.

    Uwe

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

    ttvo (26th February 2009)

  5. #4
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotPicker questions

    Thx. I got the selection drawn. Though it didn't seem to rescale when the canvas' size changes. Also, I'll split the renderImage into a separate thread.
    TNG

  6. #5
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotPicker questions

    Resize works now, . Thanks.
    TNG

  7. #6
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotPicker questions

    Hi,
    When I draw the selection rectangle, the grid and the plot comes over the rectangle. How do I set the z-order so that the selection rectangle comes over other things.

    ---------------

    I found it "SetZ" .
    Last edited by Sachtech; 28th February 2009 at 04:44.

  8. #7
    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: QwtPlotPicker questions

    Quote Originally Posted by Sachtech View Post
    How do I set the z-order so that the selection rectangle comes over other things.
    Qt Code:
    1. QwtPlotItem::setZ(...)
    To copy to clipboard, switch view to plain text mode 
    You noticed, that there are docs ?

    Uwe

Similar Threads

  1. Replies: 4
    Last Post: 25th October 2007, 12:23
  2. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  3. Some questions related to Qt tutorials
    By jamadagni in forum Newbie
    Replies: 2
    Last Post: 17th March 2007, 10:51
  4. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13:54
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

Tags for this Thread

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.