Results 1 to 3 of 3

Thread: qwt 6.1.0 - QwtPlotMarker label truncated by edge of plot

  1. #1
    Join Date
    Feb 2006
    Posts
    5
    Platforms
    Windows

    Default qwt 6.1.0 - QwtPlotMarker label truncated by edge of plot

    Hello, I have created a label for a QwtPlotMarker. The vertical line is near the right edge of the plot and is truncated by the right edge of the plot/canvas.

    Attenuation-Dialog.JPG

    How can I make the plot take into account the label and make the plot a bit bigger? Struggling along I tried this:
    m_wa_marker->setItemAttribute(QwtPlotItem::Margins, true); // more space???

    Thanks in advance for your suggestions (btw - great library!)

    cs

    Qt Code:
    1. QwtPlotMarker *m_wa_marker;
    2. void emat_attenuation_plot::set_wa_sample(double sample)
    3. {
    4. QString label = QString("WA: %1").arg(sample, 0, 'f', 1);
    5. QwtText text(label);
    6. text.setColor(Qt::blue);
    7. text.setFont(QFont("Helvetica", 10, QFont::Bold));
    8. m_wa_marker->setLabel(text);
    9. m_wa_marker->setValue(sample, 0.0);
    10. m_wa_marker->setItemAttribute(QwtPlotItem::Margins, true); // more space???
    11. }
    To copy to clipboard, switch view to plain text mode 

  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: qwt 6.1.0 - QwtPlotMarker label truncated by edge of plot

    One idea how to avoid this problem might be to implement some sort of auto alignment feature. F.e you could overload QwtPlotMarker::drawLabel(), where you change the alignment to left, when there is not enough space.

    If this is not possible you have to decide if you want to (a) extend the plot coordinate system or you want to (b) extend the margin between the end of the axis and the canvas border. IMO a) would be more natural, but here you have the problem, that the text size is in widget coordinates, while the axis is in plot coordinates. So you would always have to readjust, when the widget gets resized, or the axis is changing.

    For b) setting the QwtPlotItem::Margins flag should be the correct idea, but you also need to overload QwtPlotMarker::getCanvasMarginHint() where you return something for the right margin - depending on the text size.

    Uwe

  3. #3
    Join Date
    Feb 2006
    Posts
    5
    Platforms
    Windows

    Default Re: qwt 6.1.0 - QwtPlotMarker label truncated by edge of plot

    I did as you suggested in b) and it worked as you described. But ... it looked funny/"off-balance" since the plot stuck out only to accommodate the text. I then realized there was a much simpler solution which worked better anyway for my particular problem. Since the plot-data's character, labels and samples are mostly constant it worked very well to just plot the marker-text to the :AlignLeft side of the vertical marker-line and leave it at that. Problem solved!
    Attenuation-Dialog-new.jpg
    Nonetheless it was a good Qwt exercise for the reader in how to approach customizing the plot elements. Thanks for the help!

    cs
    cs

Similar Threads

  1. Replies: 8
    Last Post: 1st July 2013, 12:20
  2. QwtPlotMarker label position
    By mole in forum Qwt
    Replies: 4
    Last Post: 21st May 2013, 07:27
  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: 3
    Last Post: 1st December 2011, 06:29
  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.