How to show xy coordinate on QLabel widget
Hi everybody,
in my application I show the xy coordinate of the mouse near the mouse pointer.
Is it possible to get the coordinate from a QwtPicker object and manipulate to insert in a QLabel widget? I have not find anyting about this.
This is my code for show the QwtPicker
main_picker = new QwtPlotPicker(this->canvas());
picker_main = new QwtPlotPicker(this->xBottom,this->yLeft,QwtPicker::AlwaysOn, QwtPlotPicker::NoRubberBand, QwtPlotPicker::AlwaysOn,this->canvas());
QFont trackerFont = picker_main->trackerFont();
trackerFont.setFamily("Tahoma");
trackerFont.setBold(true);
trackerFont.setPointSize(18);
picker_main->setTrackerFont(trackerFont);
Thanks in advance for any help
Re: How to show xy coordinate on QLabel widget
What about connecting a slot to the QwtPlotPicker::selected(const QwtDoublePoint &) signal.
Uwe
Re: How to show xy coordinate on QLabel widget
Quote:
Originally Posted by
Uwe
What about connecting a slot to the QwtPlotPicker::selected(const QwtDoublePoint &) signal.
Uwe
Thanks for the reply Uwe.
Your solution works but only if I pressed the mouse button on the QwtPlot area.
I need to get the mouse coordinate in real time when I move the mouse.
At the moment I have not find anything for do this operation.
Matteo
Re: How to show xy coordinate on QLabel widget
you can do something with trackerText() of your picker. But it need to be figuered out how to deal with it's protected status.
Re: How to show xy coordinate on QLabel widget
Hi KosyakOFF,
I am having trouble with QwtplotPicker::trackerText() function. How can I solve this protected problem.
Cheers,
Re: How to show xy coordinate on QLabel widget
Quote:
Originally Posted by
hamid ghous
Hi KosyakOFF,
I am having trouble with QwtplotPicker::trackerText() function. How can I solve this protected problem.
Cheers,
Taking in acount that trackerText is virtual maybe you should make derieved class from picker. In it's constructor set link to your application and then reload trackerText() to transfer coordinates right to application label or something that makes more sense to you. =)
Re: How to show xy coordinate on QLabel widget
Hi to Everyone,
i want the xy-coordinates too, but i want to save it to an integer or a double to display a Marker with a mouse click.
I had connected the Signal as UWE described and the signal is working. But i did not get the values, which are shown next to the mouse at the QwtPlot. e.g. (22000, 800). I only get from d_picker->trackerPosition() something like (139,81) which seem to be the pixel coordinates of the window.
My Question is:
How can i retrieve or transform the data "behind" the pixel-coordinates {like: (22000, 800) } ?
Or which additional Signal, must i connect to get the data which is displayed next to the mouse pointer?
thanks in advance,
Astronomy
here's my code:
Code:
CPlot::CPlot() // constructor
// Crosslines of the mouse - SELECTION
d_picker
->setRubberBandPen
(QColor(Qt
::green));
d_picker
->setRubberBand
(QwtPicker::CrossRubberBand);
connect(d_picker,
SIGNAL(moved
(const QPoint &)),
SLOT(moved
(const QPoint &)));
connect(d_picker, SIGNAL(selected(const QwtPolygon &)), SLOT(selected(const QwtPolygon &)));
// connect(d_picker, SIGNAL(selected(const QwtDoublePoint &)), SLOT(selected(const QwtDoublePoint &)));
...[B] // as Uwe said..[/B]
connect(d_picker, SIGNAL(selected(const QwtDoublePoint & )), SLOT(DrawMarkers()) );
...
// My Signal of my QwtPlot derivation...
Code:
void CPlot::DrawMarkers()
{
// Here the Markers for the selection will be placed on the plot..
cSelectionMarker
->setLabel
(QString::fromLatin1("x-Selection"));
cSelectionMarker->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
cSelectionMarker->setLabelOrientation(Qt::Vertical);
cSelectionMarker
->setLinePen
(QPen(Qt
::red,
0, Qt
::DashDotLine));
int Test = 0;
// QwtDoublePoint pos;
pos = d_picker->trackerPosition();
test = pos.rx(); // only for debugging: result was 139, seem to be the coordinates of the Window
test = pos.ry(); // debugging resultwas : 81 seem to be the coordinates of the Window
test = d_picker->yAxis(); // debugging: result was 0, this comes from the constructor as a result of QwtPlot::yLeft
test = d_picker->xAxis(); // debugging: result was 2, this comes from the constructor as a result of QwtPlot::xBottom
//d_picker->trackerText(pos);
cSelectionMarker->setXValue( test ); //Set the Marker at mouseclick, not ok
// cSelectionMarker->setXValue( 23000 ); //hardcoded Test, ok
cSelectionMarker->attach(this);
replot();
}
Re: How to show xy coordinate on QLabel widget
Quote:
Originally Posted by
KosyakOFF
Taking in acount that trackerText is virtual maybe you should make derieved class from picker. In it's constructor set link to your application and then reload trackerText() to transfer coordinates right to application label or something that makes more sense to you. =)
Hi,
I'm using QwtPlotPicker which is derived from QwtPicker.
i quess the member Function QwtPicker::trackerText() does the transformation from the QwtPlot Widget and prints the x-y values near the mouse pointer. In qwt_picker.cpp i found: QwtText text = trackerText(d_data->trackerPosition);
If i want in my SW to do:
const QwtText label = d_picker->trackerText( d_picker->trackerPosition() ); the compiler says »virtual QwtText QwtPlotPicker::trackerText(const QPoint&) const« is protected.
OK so for this i must subclass: I'm not sure how to do it in a correct way. Respective how much i need to subclass...
1 Try) i tried to subclass and add only QwtText trackerText(const QPoint &) const; to be public. But i have to make my own construktors and this was filled with some errors. (it compiled but somehow, some of the functionality was missing during runtime..)
2 Try) i did copy and paste all of qwt_plot_picker.h and qwt_plot_picker.cpp , renamed the class in CMyQwtPlotPicker and all of the CMyQwtPlotPicker::Memberfunctions, and made QwtText trackerText(const QPoint &) const public, but here i got a lot of errors from the Linker??
/cmyqwtplotpicker.cpp:270: undefined reference to `CMyQwtPlotPicker::moved(QPointF const&)'
...
obvious the Signal moved Function cannot be found.. it is defined in *.h as
void moved(const QwtDoublePoint &pos); but it is not implemented in the *.cpp But in the Original QwtPlotPicker this is done in exact the same way?
Any hints why a simple renaming doesn't work?
thanks in advance
Astronomy
Re: How to show xy coordinate on QLabel widget
Well, I used first method but didn't set trackerText() public. Instead I placed pointer to my app in constructor of picker and in trackerText() function I transfer postion coordinates to my app function which is setting text to QLabel. But I'm sure this is very bad way to perform such task.