Results 1 to 2 of 2

Thread: Add outline/shadow to QwtText

  1. #1
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Add outline/shadow to QwtText

    I have a QwtPlotMarker that I configure using QwtFont and QwtText to get the font/color that I desire. The data is being displayed in image mode using a QwtPlotSpectrogram. The problem is the marker text is easy/hard to read depending on the current color behind it. Just changing the font color doesn't help because the image color behind it is constantly changing.

    I'd like to add a single-pixel border just around the text (not a box) to help the text 'pop'. I came across the QGraphicsDropShadowEffect class in Qt which might work, but QwtText doesn't seem to have that capability natively.

    Here's my current code to create the QwtPlotMarker. Nothing fancy, but in case it helps....
    Qt Code:
    1. QwtPlotMarker selectedPoint = new QwtPlotMarker();
    2. QwtText labelText("");
    3. labelText.setColor(Qt::black);
    4. QFont labelFont("Times", 12, QFont::Black);
    5. labelText.setFont(labelFont);
    6. selectedPoint->setLabel(labelText);
    7. selectedPoint->setLabelAlignment(Qt::AlignTop);
    8. selectedPoint->attach(this);
    To copy to clipboard, switch view to plain text mode 
    I then update the labelText as new data is received via external message.

    Any ideas or suggestions to point me in the right direction are appreciated.
    Bryan

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

    Default Re: Add outline/shadow to QwtText

    One option might be to add a semitransparent white background - like it is done for tracker text in the spectrogram example.

    Otherwise you could try to overload QwtPlotMarker::drawLabel somehow like this:

    Qt Code:
    1. virtual void YourMarker::drawLabel( QPainter *painter, const QRectF &canvasRect, const QPointF &pos ) const
    2. {
    3. painter->save();
    4. painter->setPen( Qt::black );
    5. QwtPlotMarker::drawLabel( painter, canvasRect, pos + QPointF( -1, 1 ) );
    6. painter->restore();
    7.  
    8. QwtPlotMarker::drawLabel( painter, canvasRect, pos );
    9. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

Similar Threads

  1. QwtText background padding
    By Maximus2 in forum Qwt
    Replies: 9
    Last Post: 6th December 2018, 07:36
  2. Replies: 5
    Last Post: 31st May 2016, 09:07
  3. Replies: 3
    Last Post: 2nd May 2015, 17:14
  4. Replies: 0
    Last Post: 21st November 2013, 06:39
  5. Replies: 2
    Last Post: 16th March 2012, 06:55

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.