Results 1 to 9 of 9

Thread: How to show xy coordinate on QLabel widget

  1. #1
    Join Date
    Jul 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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

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

    Default Re: How to show xy coordinate on QLabel widget

    What about connecting a slot to the QwtPlotPicker::selected(const QwtDoublePoint &) signal.

    Uwe

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

    Astronomy (9th February 2010)

  4. #3
    Join Date
    Jul 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to show xy coordinate on QLabel widget

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

  5. #4
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  6. The following user says thank you to KosyakOFF for this useful post:

    Astronomy (10th February 2010)

  7. #5
    Join Date
    Jun 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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,

  8. #6
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to show xy coordinate on QLabel widget

    Quote Originally Posted by hamid ghous View Post
    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. =)

  9. #7
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question 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:

    Qt Code:
    1. CPlot::CPlot() // constructor
    2.  
    3. // Crosslines of the mouse - SELECTION
    4. d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::PointSelection | QwtPicker::DragSelection,
    5. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, this->canvas());
    6. d_picker->setRubberBandPen(QColor(Qt::green));
    7. d_picker->setRubberBand(QwtPicker::CrossRubberBand);
    8. connect(d_picker, SIGNAL(moved(const QPoint &)), SLOT(moved(const QPoint &)));
    9. connect(d_picker, SIGNAL(selected(const QwtPolygon &)), SLOT(selected(const QwtPolygon &)));
    10. // connect(d_picker, SIGNAL(selected(const QwtDoublePoint &)), SLOT(selected(const QwtDoublePoint &)));
    11.  
    12. ...[B] // as Uwe said..[/B]
    13. connect(d_picker, SIGNAL(selected(const QwtDoublePoint & )), SLOT(DrawMarkers()) );
    14. ...
    To copy to clipboard, switch view to plain text mode 

    // My Signal of my QwtPlot derivation...
    Qt Code:
    1. void CPlot::DrawMarkers()
    2. {
    3. // Here the Markers for the selection will be placed on the plot..
    4. QwtPlotMarker *cSelectionMarker = new QwtPlotMarker();
    5. cSelectionMarker->setLabel(QString::fromLatin1("x-Selection"));
    6. cSelectionMarker->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    7. cSelectionMarker->setLabelOrientation(Qt::Vertical);
    8. cSelectionMarker->setLineStyle(QwtPlotMarker::VLine);
    9. cSelectionMarker->setLinePen(QPen(Qt::red, 0, Qt::DashDotLine));
    10.  
    11. int Test = 0;
    12. // QwtDoublePoint pos;
    13. QPoint pos;
    14. pos = d_picker->trackerPosition();
    15. test = pos.rx(); // only for debugging: result was 139, seem to be the coordinates of the Window
    16. test = pos.ry(); // debugging resultwas : 81 seem to be the coordinates of the Window
    17.  
    18.  
    19. test = d_picker->yAxis(); // debugging: result was 0, this comes from the constructor as a result of QwtPlot::yLeft
    20. test = d_picker->xAxis(); // debugging: result was 2, this comes from the constructor as a result of QwtPlot::xBottom
    21.  
    22. //d_picker->trackerText(pos);
    23.  
    24.  
    25. cSelectionMarker->setXValue( test ); //Set the Marker at mouseclick, not ok
    26. // cSelectionMarker->setXValue( 23000 ); //hardcoded Test, ok
    27. cSelectionMarker->attach(this);
    28. replot();
    29. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Astronomy; 9th February 2010 at 18:28.

  10. #8
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show xy coordinate on QLabel widget

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

  11. #9
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  12. The following user says thank you to KosyakOFF for this useful post:

    Astronomy (11th February 2010)

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Show dock widget frame/border
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 21st May 2009, 10:04
  3. How to show the widget?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 08:43
  4. Replies: 4
    Last Post: 4th February 2008, 06:16
  5. How to show custom widget in TreeView's cell :-/
    By WolfMM in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 11:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.