Results 1 to 6 of 6

Thread: Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

  1. #1
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

    We're attempting to port our use of Qwt from Qwt 5.2.3 to Qwt 6.1.2. One difficulty we're having is with conventional legend items. See this illustration:

    QwtLegendLabelPort.png

    The 6.1 QwtLegendLabel isn't showing the symbol. Nor the line. Our Qwt 5.2 application code increases the horizontal width of the line with a call to QwtLegendItem::setIdentifierWidth (32) -- there doesn't seem to be an analogous method available in QwtLegendLabel. Looking at QwtLegendLabel and QwtTextLabel source code, I'm not seeing anything that would actually draw those two graphical components (line and symbol).

    What am I missing? If we need to completely implement our own drawing of these legend things, what might be the best approach, in Qwt 6.1?

    Thank you in advance.
    Last edited by philw; 19th October 2015 at 23:54.

  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: Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

    The content of the legend is provided by the items now - see QwtPlotItem::legendXYZ(). QwtPlotCurve reimplements f.e legendIcon(), providing an icon, that depends on QwtPlotCurve::LegendAttributes.

    Uwe

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

    philw (21st October 2015)

  4. #3
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

    Thank you for your response, Uwe. I did try setting the QwtPlotItem's icon size arbitrarily large ... with this call in my QwtPlotItem subclass' constructor: setLegendIconSize (QSize (32, 20)) ... hoping that that would provide the Qwt 5.2 legend graphic for the item. That results in just a black rectangle of that size, as the icon for that legend label.

    Is the intention that I need to DRAW that icon myself -- showing both the line color and thickness, and the symbol (see my 5.2 example in the original post) -- in a method override for the QwtGraphic QwtPlotItem::legendIcon (int index, const QSizeF& size) const virtual method? We're supposed to code that ourselves? (Not that that's inordinately difficult. It's just somewhat astonishing. So I want to make sure I'm on the right track).

    Thank you again.

  5. #4
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

    I do now see legendIcon() virtual method provisions for QwtPlotItem. (I think we're gonna be more on our own for QwtPlotMarkers; we are conditionally showing legend items for those too). But there doesn't seem to be an elegant way to reliably (persistently) set a larger width for the legend icon, as the effect of calling QwtPlotItem::setLegendIconSize() is blown away by various API calls -- not just the calls mentioned in the comment below -- this is from our QwtPlotItem subclass' constructor:

    Qt Code:
    1. // Set attributes uses by QwtPlotCurve::legendIcon().
    2. setLegendAttribute (QwtPlotCurve::LegendShowLine, true);
    3. setLegendAttribute (QwtPlotCurve::LegendShowSymbol, true);
    4. setLegendAttribute (QwtPlotCurve::LegendShowBrush, true);
    5.  
    6. // Ensure a minimum legend icon width of 32 pixels. Note that this must
    7. // be done after the calls to QwtPlotCurve::setLegendAttribute() because
    8. // that method has a side-effect of re-initializing the legend icon size.
    9.  
    10. const QSize origSize = legendIconSize();
    11. if (origSize.width() < 32)
    12. setLegendIconSize (QSize (32, origSize.height()));
    To copy to clipboard, switch view to plain text mode 

    That is, I see that, subsequently calling QwtPlotCurve::setSymbol() -- which occurs asynchronously, as we have provided selection of that in our application-level plot dialog -- also blows away the icon size. This occurs internally, in a call to the local function, static void qwtUpdateLegendIconSize (QwtPlotCurve*).

    I guess, this could be solved in the future with an enhancement to Qwt (QwtPlotCurve), to be able to specify a minimum legend icon width. But short of that, I think we need to keep on applying a minimum width we want each time we call a setter in the QwtPlotCurve API.

  6. #5
    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: Can Qwt 6.1's QwtLegendLabel give the appearance of Qwt 5.2's QwtLegendItem?

    Yes indeed there is no minimum size attribute for the legend icon. But the following code should do what you need:

    Qt Code:
    1. virtual QwtGraphic YourCurve::legendIcon( int index, const QSizeF &size ) const
    2. {
    3. return QwtPlotCurve::legendIcon( index, QSizeF( qMax( size.width(), 32.0 ), size.height() ) );
    4. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

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

    philw (21st October 2015)

  8. #6
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Alternative implementation for QwtPlotMarker::legendIcon() [Qt 6.1.2]

    Uwe, thanks for all your assistance, and your great work on Qwt.

    I'd like to share my re-implementation (minor simplification) of QwtPlotMarker::legendIcon(). The original 6.1.2 implementation draws a vertical piece for Markers having the "vertical line" or "cross" marker style. I felt that, just as for Curves' legend icons, a simpler linear-only horizontal rendering of the Marker's configuration ... line color and width, and symbol style and size ... would be ideal for Markers' legend icons as well.


    Here's an example showing a QwtPlotMarker (having a "Cross" marker style) in the Legend. (This is with the code shown below) ...

    MarkersAndCurvesInLegend.png


    So, this is a simplification of the original implementation which we're using. Other than checking whether any line is drawn for the Marker, this implementation ignores the Marker's Style property ... compare to QwtPlotMarker::legendIcon() in src/qwt_plot_marker.cpp ...

    Qt Code:
    1. // virtual from QwtPlotItem
    2. QwtGraphic PlotMarker::legendIcon (int index, // (ignore, only one)
    3. const QSizeF& iconSize) const
    4. {
    5. // call base class method (don't).
    6. //-- QwtGraphic graphic = QwtPlotMarker::legendIcon (index, iconSize);
    7. //-- return graphic;
    8.  
    9. // The following is adapted from the QwtPlotMarker::legendIcon()
    10. // implementation (from Qwt 6.1.2). We really don't want to attempt
    11. // to draw "vertical" components of the marker appearance, i.e. the
    12. // vertical line, if the marker has the "VLine" or "Cross" style.
    13. // Those nuances have been left out of this adaptation.
    14.  
    15. Q_UNUSED (index);
    16.  
    17. if (iconSize.isEmpty())
    18. return QwtGraphic();
    19.  
    20. QwtGraphic icon;
    21. icon.setDefaultSize (iconSize);
    22. icon.setRenderHint (QwtGraphic::RenderPensUnscaled, true);
    23.  
    24. QPainter painter (&icon);
    25. painter.setRenderHint (QPainter::Antialiasing,
    26. testRenderHint(QwtPlotItem::RenderAntialiased));
    27.  
    28. const QwtPlotMarker::LineStyle markerStyle = lineStyle();
    29. const QPen& penRef = linePen();
    30. const QwtSymbol* symb = symbol();
    31.  
    32. if (markerStyle != QwtPlotMarker::NoLine)
    33. {
    34. painter.setPen (penRef);
    35. const double y = 0.5 * iconSize.height();
    36. QwtPainter::drawLine (&painter, 0.0, y, iconSize.width(), y);
    37. }
    38.  
    39. if (symb)
    40. {
    41. const QRect rect (0.0, 0.0, iconSize.width(), iconSize.height());
    42. symb->drawSymbol (&painter, rect);
    43. }
    44.  
    45. return icon;
    46. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by philw; 22nd October 2015 at 06:51.

Similar Threads

  1. Replies: 1
    Last Post: 16th April 2015, 07:00
  2. More information about QwtLegendLabel
    By Sangfeust in forum Qwt
    Replies: 2
    Last Post: 9th February 2015, 09:46
  3. Replies: 1
    Last Post: 19th September 2014, 08:56
  4. QwtPlotLegendItem and QwtLegendItem
    By jesse_mark in forum Qwt
    Replies: 3
    Last Post: 14th November 2012, 07:10
  5. Replies: 2
    Last Post: 24th January 2012, 12:52

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.