Results 1 to 14 of 14

Thread: Draw a circle or sequare/rectange by mouse on qwtpolt???

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Draw a circle or sequare/rectange by mouse on qwtpolt???

    Hello,
    I want to draw a circle/square/rectangle on qwtpolt using the mouse, so the user can draw it anywhere on the polt with any size he wants.

    is there any way or idea of how can i do it ???

    Thank you,

    Jesse

  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: Draw a circle or sequare/rectange by mouse on qwtpolt???

    Maybe you are looking for QwtPlotPicker.

    Uwe

  3. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    I am still learning about qwt, do you know any example or could you explain more of how can i use the PoltPicker ??
    I know it gives the mouse pos for me, but how i show a square that gets bigger as the user drag the mouse more??

    just the like the way when u draw a square in the painter.

    thank you

  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: Draw a circle or sequare/rectange by mouse on qwtpolt???

    F.e every QwtPlotZoomer is a picker that draws a rectangle.

    Uwe

  5. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    i was looking at the bode example, it does has a piker with zoomer.
    which is using (QwtPicker::RectRubberBand) .. // "d_zoomer[0]->setRubberBand(QwtPicker::RectRubberBand);"
    but i dont need the zoomer and i want the rect to stay on the canvas when i draw it.
    so i think i need a piker and set its rubber band to rect rubberband, but how i make the rect stays on the plot ??
    thank you so much


    Added after 13 minutes:


    I use a piker to give me the the mouse position


    Qt Code:
    1. QwtPlotPicker *picker = new QwtPlotPicker(QwtPlot::xBottom,QwtPlot::yLeft,this->canvas());
    2. picker->setStateMachine(new QwtPickerTrackerMachine);
    3. picker->setTrackerMode(QwtPicker::AlwaysOn);
    4.  
    5. // i added these lines not sure if this is the way tho ???
    6. picker->setRubberBand(QwtPicker::RectRubberBand);
    7. picker->setRubberBandPen(QColor(Qt::green));
    To copy to clipboard, switch view to plain text mode 



    i have this piker and set the rubberband to rect rubber
    how i active it or disactive it ?? i mean make show and stay on the polt? and how i get its points ?

    Thank you
    Last edited by jesse_mark; 26th September 2012 at 15:51.

  6. #6
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    i edite my code and i was able to see the rect on my plot, but when i finisd the rect disappear , i would like to keep it shown and have access to its valus(points)

    Qt Code:
    1. picker = new QwtPlotPicker(QwtPlot::xBottom,QwtPlot::yLeft,this->canvas());
    2. // picker->setStateMachine(new QwtPickerTrackerMachine);
    3. picker->setStateMachine(new QwtPickerClickRectMachine);
    4. picker->setTrackerMode(QwtPicker::ActiveOnly);
    5. picker->setTrackerPen(QColor(Qt::white));
    6.  
    7. picker->setRubberBand(QwtPicker::RectRubberBand);
    8. picker->setRubberBandPen(QColor(Qt::green));
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    Implement a custom QwtPlotItem that will represent your rectangle. Use a QwtPlotPicker (or QwtPicker) to allow the user to choose a rectangle. Once the selection is complete, create an instance of your plot item and place it on the plot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    embeddedmz (26th May 2021)

  9. #8
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    Thank Wysota,

    I used QwtPlotPicker and as i read from the qwtplotpicker a selected signal we be emitted once the selection is done.

    so i connected it like:


    Qt Code:
    1. // [I]this[/I] is the MainWin
    2. connect(plot->picker,SIGNAL(selected(QVector<QPointF>)),this,SLOT(DrawSelection(QVector<QPointF> SelectionPoints)));
    To copy to clipboard, switch view to plain text mode 

    and i have the slot on the mainwindow
    Qt Code:
    1. void MainWin::DrawSelection(QVector<QPointF> SelectionPoints)
    2. {
    3. /// draw the points
    4. }
    To copy to clipboard, switch view to plain text mode 

    but im the single is not emitted
    and when i run it can see the slot saying >>
    Qt Code:
    1. [I]object::connect: No such slot MainWin::DrawSelection(QVector<QPointF> SelectionPoints)[/I
    To copy to clipboard, switch view to plain text mode 
    ]

    so can u please let me know what is the mistake im making ??

    Thanks
    Last edited by jesse_mark; 26th September 2012 at 22:03.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    I think the message is pretty much self explanatory -- you don't have a slot called "DrawSelection" in your "MainWin" class. Usually this means you either forgot the Q_OBJECT macro or you didn't declare the method as a slot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #10
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    I do have this method in the MainWin header under

    public slots:
    void DrawSelection( QVector<QPointF> SelectionPoints);


    and i do have other methods using them as slots and i have no problem.

    but what do u exactly mean by Q_OBJECT macro ? I have have Q_OBJECT in header, but to be honest i don't really know exactly what its for .

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    Ah, I read the error message again and I noticed what was wrong. Remove the variable name from the slot signature in the connect() statement.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #12
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    Thanks the error message not there, but the signal is not triggred , after i do my selection the rect and every thing but the signal is not triggered??

    OK i found in the bode example that come with the qwt library

    used a picker and the selected signal

    this way :

    Qt Code:
    1. // mainwindow header
    2. private Q_SLOTS:
    3. void selected(const QPolygon &);
    4.  
    5. //mainwindow cpp
    6. ...
    7. connect(d_picker, SIGNAL(selected(const QPolygon &)),SLOT(selected(const QPolygon &)));
    8. ....
    9. ....
    10. void MainWindow::selected(const QPolygon & )
    11. {
    12.  
    13. qDebug()<<" I got triggred ";
    14. ................
    15. }
    To copy to clipboard, switch view to plain text mode 


    this signal was triggered fine, but why the

    connect(picker, SIGNAL(selected(const QVector<QPointF> &)), SLOT(DrawSelection(const QVector<QPointF> &)));
    was not triggered ???
    Last edited by jesse_mark; 27th September 2012 at 16:09.

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    You probably have a Rect picker, not a Point picker machine attached to the picker.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. The following user says thank you to wysota for this useful post:

    jesse_mark (27th September 2012)

  16. #14
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a circle or sequare/rectange by mouse on qwtpolt???

    yes i have a rect picker, put i though the

    Qt Code:
    1. selected(const QVector<QPointF> &)
    To copy to clipboard, switch view to plain text mode 

    will return a vector with all the points that represent the rect.
    i tried to use the
    Qt Code:
    1. selected( const polygon &p)
    To copy to clipboard, switch view to plain text mode 
    ,

    but when i print the first point in the pollygon
    Qt Code:
    1. Qdebug() << p.at(0)
    To copy to clipboard, switch view to plain text mode 
    it gave me different points than the qwt points where i made the selection.

    Do the points in the return polygon in the selected signal, has the same points in qwt ?? and if so how i can access all the points that are returned in the polygon ??

    Thank you


    Added after 28 minutes:


    Thank you Wysota and Uwe so much,

    I used selected(QRectF) and got all my points
    thanks again
    Last edited by jesse_mark; 27th September 2012 at 17:09.

Similar Threads

  1. how to draw a circle using qml
    By hema in forum Qt Quick
    Replies: 2
    Last Post: 8th August 2016, 12:48
  2. Re: Draw circle in a qframe
    By vinithr in forum Newbie
    Replies: 12
    Last Post: 9th July 2012, 06:52
  3. draw a circle
    By NewLegend in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2010, 16:01
  4. How to draw a special circle pie
    By parnedo in forum Qt Programming
    Replies: 7
    Last Post: 3rd July 2009, 15:25
  5. What is the fastest way to draw a circle ?
    By Vladimir in forum Qt Programming
    Replies: 18
    Last Post: 6th September 2007, 17:26

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.