Results 1 to 10 of 10

Thread: How to draw soft shadow with QPainter?

  1. #1
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to draw soft shadow with QPainter?

    Hi
    I need to draw something like this (see picture). I don't know, what to make good use - blured lines or gradient or something else
    Please, help me
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    The easiest way would be to use a linear gradients in combination with painter opacity for the shadow edges.

    You could look at the Gradients example in the Qt Demos. It is not exactly what you need, but you should find something in there.

    Regards.

  3. #3
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to draw soft shadow with QPainter?

    Quote Originally Posted by marcel View Post
    The easiest way would be to use a linear gradients in combination with painter opacity for the shadow edges.

    You could look at the Gradients example in the Qt Demos. It is not exactly what you need, but you should find something in there.

    Regards.
    I tried to work with gradients, but result is not accurate. Corners are not rounded and it look not beautifully
    Maybe other way?
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw soft shadow with QPainter?

    Try the attached example (it works for backgroundless pixmaps as well and with little effort it should work for semi-transparent ones too). Use right and left mouse button to switch between different drawing modes.

    If you want to change the way the shadow looks, adjust the filter.
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw soft shadow with QPainter?

    Here is an improved version. Optimised and working correctly for full alpha channeled images.
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    This is very very slow.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    There was some shadows example on Trolltech labs(Graphics/Dojo)
    You can find it here

  8. #8
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    Thank you for concern.

    This example is rendering SVGs. But I want image files to be rendered with shadow. The old one, provided by Wysota, is doing same but that is too slow to be used.

  9. #9
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    Well, you could optimize it. But firstly is it really too slow? Try drawing the shadow into a separate pixmap in the beginning and then just render it in the paintEvent(instead of generating it every time).
    If that's still too slow for you, there are multiple ways of optimizing the function.

  10. #10
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw soft shadow with QPainter?

    Thank you mate, this is very good example,
    I gonna use it.

Similar Threads

  1. QPainter draw rounded arrow
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2006, 12:32
  2. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06
  3. Replies: 7
    Last Post: 20th March 2006, 20:03
  4. Draw a rectangle alternating two colors with qPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 23:12
  5. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:18

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.