Results 1 to 9 of 9

Thread: Change the position of Label of the QwtPlotMarker

  1. #1
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Change the position of Label of the QwtPlotMarker

    Hello,

    i am trying to change the position of the label of the qwtplotmarker. (User will drag it to another position but only label should move. not the marker.)

    is it possible?

    if no, what can i do? Can i use QwtText and add it to any positon(x,y) on the plot?

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

    Default Re: Change the position of Label of the QwtPlotMarker

    1. Drag an drop could be done using a QwtPlotPicker, where the text label is used as tracker text. Or you can do it like in the itemeditor example.
    2. The position of the label is always aligned to the marker position, but in your case you probably want to set an offset in pixels. For this you have to derive from QwtPlotMarker and overload QwtPlotMarker::drawLabel().



    Uwe

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

    kerberos84 (28th June 2013)

  4. #3
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the position of Label of the QwtPlotMarker

    Hello,
    I have tried to sub-class and override draw method or drawLabel method. But these two methods are "const". I can not save the label position, because these are "const" methods.

    I just have to save the label coordinates, in order to select it and move to another position like in the itemeditor example.

    Do you have any suggestions?

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

    Default Re: Change the position of Label of the QwtPlotMarker

    There are ways to drive around the constness in C++, but they are of no importance here as a draw method is for drawing - not for changing a position.

    You derived class has to add a new member for the offset ( in pixels ) from the marker position, that is used by your overloaded drawLabel method. Setting the offset has to be done on a selected signal of the picker.

    Uwe

  6. #5
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the position of Label of the QwtPlotMarker

    Hello i am using qwt 5.2 and qt 4.6 versions.

    1) I checked the itemeditor example and hence qwt_widget_overlay class does not exist in qwt 5.2 i copied it to my project and tried to compile it.

    But when i compile it i get a linking error for the line "QMetaObject::invokeMethod" line. I think the method trying to be invoked does not exist in my qwt version, right? (QwtPlotCanvas::borderPath).

    What can i do in this situation? Please help, i have written everything for moving label, only this left.

    Qt Code:
    1. void QwtWidgetOverlay::draw( QPainter *painter ) const
    2. {
    3. QWidget *widget = const_cast< QWidget *>( parentWidget() );
    4. if ( widget )
    5. {
    6. painter->setClipRect( parentWidget()->contentsRect() );
    7.  
    8. // something special for the plot canvas
    9. QPainterPath clipPath;
    10.  
    11. ( void )QMetaObject::invokeMethod(
    12. widget, "borderPath", Qt::DirectConnection,
    13. Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, rect() ) );
    14.  
    15. if (!clipPath.isEmpty())
    16. {
    17. painter->setClipPath( clipPath, Qt::IntersectClip );
    18. }
    19. }
    20.  
    21. drawOverlay( painter );
    22. }
    To copy to clipboard, switch view to plain text mode 

    2) in the QwtWidgetOverlay class it calls "QwtPlotCanvas::invalidateBackingStore" method. Again this method does not exist in qwt 5.2. There is a method called "invalidateCache" in qwt 5.2.
    Does it do the similar things? Can i use it?
    Last edited by kerberos84; 27th June 2013 at 14:35.

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

    Default Re: Change the position of Label of the QwtPlotMarker

    1. The tracker text of the QwtPlotPicker is implemented as a widget overlay moving a text around. If you overload its trackerText() method - always returning the text of the selected label - you would have an implementation without having to backport from Qwt 6.1.
    2. When using your code above you can simply remove the lines 8-18. They are for setting a clip for a canvas with rounded borders - something you don't have in Qwt 5.x.
    3. Yes you can use invalidateCache instead.


    Uwe

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

    kerberos84 (28th June 2013)

  9. #7
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the position of Label of the QwtPlotMarker

    Thanks for your answers Uwe,

    I have managed it by backporting qwtwidgetoverlay class to my code.

    I have another question. There is a zoom function in my plot so i use qwtplotzoomer to zoom in. So currently while i am dragging the label it is also drawing the zoom rectangle and when i release mouse button it zooms in. How can i disable Zooming while i am dragging a label?

    I tried to call zoomer->setEnable(false) when mousePressed and acceptted dragging and zoomer->setEnable(true) when mouse is released but it does not work.

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

    Default Re: Change the position of Label of the QwtPlotMarker

    Quote Originally Posted by kerberos84 View Post
    There is a zoom function in my plot so i use qwtplotzoomer to zoom in. So currently while i am dragging the label it is also drawing the zoom rectangle and when i release mouse button it zooms in. How can i disable Zooming while i am dragging a label?
    Well using the same mouse button for zooming and moving a marker is IMHO not a good idea - at least from the point of view of usability. So I recommend to use different modes or mouse button/key combinations.

    But if you really need to do so: both input handlers install an event filter for the plot canvas.


    • Event filters are called in reverse order to how they have been installed.
    • When an event filter returns true the event it is not propagated any further


    So you could simply set up the zoomer first and return true from the event filter of your marker editor, when a click position matches a label.

    Uwe

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

    kerberos84 (1st July 2013)

  12. #9
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the position of Label of the QwtPlotMarker

    Thanks for your answers.

    I decided to use dragging with a mouse click + key combinitaion.

Similar Threads

  1. QwtPlotMarker label position
    By mole in forum Qwt
    Replies: 4
    Last Post: 21st May 2013, 07:27
  2. Replies: 2
    Last Post: 7th June 2012, 13:04
  3. Qwt: Unable to draw the label from qwtplotmarker?
    By sonulohani in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2012, 13:55
  4. Replies: 5
    Last Post: 11th January 2011, 06:37
  5. make label of QwtPlotMarker invisible
    By rambo83 in forum Qwt
    Replies: 1
    Last Post: 26th November 2009, 12:39

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