Results 1 to 10 of 10

Thread: How to draw soft shadow with QPainter?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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

  3. #3
    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.

  4. #4
    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

  5. #5
    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.

  6. #6
    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.

  7. #7
    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
  •  
Qt is a trademark of The Qt Company.