View Full Version : Draw a circle or sequare/rectange by mouse on qwtpolt???
jesse_mark
25th September 2012, 20:28
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
Uwe
25th September 2012, 21:34
Maybe you are looking for QwtPlotPicker.
Uwe
jesse_mark
25th September 2012, 22:17
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
Uwe
26th September 2012, 06:42
F.e every QwtPlotZoomer is a picker that draws a rectangle.
Uwe
jesse_mark
26th September 2012, 15:37
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
QwtPlotPicker *picker = new QwtPlotPicker(QwtPlot::xBottom,QwtPlot::yLeft,this->canvas());
picker->setStateMachine(new QwtPickerTrackerMachine);
picker->setTrackerMode(QwtPicker::AlwaysOn);
// i added these lines not sure if this is the way tho ???
picker->setRubberBand(QwtPicker::RectRubberBand);
picker->setRubberBandPen(QColor(Qt::green));
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
jesse_mark
26th September 2012, 20:05
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)
picker = new QwtPlotPicker(QwtPlot::xBottom,QwtPlot::yLeft,this->canvas());
// picker->setStateMachine(new QwtPickerTrackerMachine);
picker->setStateMachine(new QwtPickerClickRectMachine);
picker->setTrackerMode(QwtPicker::ActiveOnly);
picker->setTrackerPen(QColor(Qt::white));
picker->setRubberBand(QwtPicker::RectRubberBand);
picker->setRubberBandPen(QColor(Qt::green));
wysota
26th September 2012, 20:45
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.
jesse_mark
26th September 2012, 21:55
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:
// this is the MainWin
connect(plot->picker,SIGNAL(selected(QVector<QPointF>)),this,SLOT(DrawSelection(QVector<QPointF> SelectionPoints)));
and i have the slot on the mainwindow
void MainWin::DrawSelection(QVector<QPointF> SelectionPoints)
{
/// draw the points
}
but im the single is not emitted
and when i run it can see the slot saying >>
object::connect: No such slot MainWin::DrawSelection(QVector<QPointF> SelectionPoints)
so can u please let me know what is the mistake im making ??
Thanks
wysota
26th September 2012, 22:28
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.
jesse_mark
26th September 2012, 22:45
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 .
wysota
26th September 2012, 22:49
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.
jesse_mark
27th September 2012, 14:45
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 :
// mainwindow header
private Q_SLOTS:
void selected(const QPolygon &);
//mainwindow cpp
...
connect(d_picker, SIGNAL(selected(const QPolygon &)),SLOT(selected(const QPolygon &)));
....
....
void MainWindow::selected(const QPolygon & )
{
qDebug()<<" I got triggred ";
................
}
this signal was triggered fine, but why the
connect(picker, SIGNAL(selected(const QVector<QPointF> &)), SLOT(DrawSelection(const QVector<QPointF> &)));
was not triggered ???
wysota
27th September 2012, 16:25
You probably have a Rect picker, not a Point picker machine attached to the picker.
jesse_mark
27th September 2012, 17:09
yes i have a rect picker, put i though the
selected(const QVector<QPointF> &)
will return a vector with all the points that represent the rect.
i tried to use the
selected( const polygon &p) ,
but when i print the first point in the pollygon
Qdebug() << p.at(0)
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.