Results 1 to 3 of 3

Thread: qwtplot->print() removes dummy markers from legend

  1. #1
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default qwtplot->print() removes dummy markers from legend

    First some background:
    I essentially have a scrollbar to shift between different plots (1 qwt plot with one curve attached but I simply change the data the curve points to when the scroll bar is moved). Works fine. Depending on the data set being plotted I have a variable number of qwtplotmarkers that are plotted. When I move the scroll bar to change to a new plot I delete the old markers and create new ones. This works fine as well.

    Since I am deleting and creating new markers I can't simply attach them to the legend. What I did was create a dummy marker and add it to the legend like so:

    dummyMarker is declared in header (QwtPlotMarker *dummyMarker)
    lgndDummy is a QwtLegendCurveItem (see newest repository if using qwt 5.2.0) set as checkable

    Qt Code:
    1. dummyMarker = new QwtPlotMarker;
    2. dummyMarker->attach(mainPlot);
    3.  
    4. legend->insert(dummyMarker,lgndDummy);
    To copy to clipboard, switch view to plain text mode 

    I then use lgndDummy's signal "checked" to toggle whether the actual markers I attached to plot are shown or hidden. This works fine.

    When I go to save an image of the plot using the "print all" options and the print() function I found that this function removes these dummy items from the legend (the markers are still visible on the plot). This occurs before the image is saved as the image only shows the curve in the legend.

    So my question is: Is there a better way to do this or something I can do to prevent plot->print() from removing my dummy legend items?

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

    Default Re: qwtplot->print() removes dummy markers from legend

    Derive from QwtPlotMarker, and implement updateLegend(). Then enable QwtPlotItem::Legend for one of your markers.
    Another solution is to implement a dummy plot item, that paints nothing on the canvas, but implements the updateLegend() method.

    Uwe

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

    Ban-chan (27th October 2009)

  4. #3
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qwtplot->print() removes dummy markers from legend

    Got it working! Thanks Uwe.

Similar Threads

  1. Replies: 2
    Last Post: 5th December 2008, 20:11

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.