Results 1 to 4 of 4

Thread: Painter opacity problem

  1. #1
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Painter opacity problem

    My code is:
    Qt Code:
    1. QPainter painter(this);
    2. painter.setOpacity(opacity/255.0);
    3. painter.setBrush(QColor(0,0,0));
    4. painter.save();
    5. painter.setPen(QPen(QBrush(QColor(0,0,0)), 5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
    6. double meret = 60.0;
    7. painter.drawArc(QRectF(-meret, -meret, meret*2, meret*2),0*16,360*16);
    8. painter.restore();
    9. painter.setPen(Qt::NoPen);
    10. painter.drawRect(QRectF(-5, -meret, 10, meret*2));
    To copy to clipboard, switch view to plain text mode 

    The end result is:
    74391548.jpg

    But I want this:
    nvtelen1j.jpg

    How can I do that with drawArc and drawRect?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Painter opacity problem

    I'm not sure what value in opacity, but you saw this, right?
    The value should be in the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painter opacity problem

    0 to 255. But isn't that the problem. The problem is the next shortly:

    Without opacity (painter.setOpacity(220/255.0) is perfect:


    But I used opacity:


    I would like to this (Photoshop):


    So if you add opacity to the first picture (like in photoshop and if the 3 layers (3 Ellipse) are rasterized), the result is the third picture, but in Qt the result is the second (like in photoshop and the 3 layers are not rasterized).
    How can I get the third picture, if I use the first and I add to it opacity after the drawing?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Painter opacity problem

    I see. (Misslooked intersection in your first post). Qt's QPainter works correct. For your goal you need to apply opacity to whole scene. In this case you;d probably need to render scene into some buffer, QPixmap or QImage and then render it with needed opacity.
    You can also play with Composition modes...
    Last edited by spirit; 22nd August 2012 at 15:45.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. problem in painter fillRect
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 13:43
  2. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 13:47
  3. Some problem with painter's fillpath() method
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 30th June 2008, 13:31
  4. painter problem in new Qt-4.2.3 installation
    By impeteperry in forum Installation and Deployment
    Replies: 2
    Last Post: 2nd May 2007, 05:34
  5. problem of opacity for textLabel
    By Stephano in forum Qt Programming
    Replies: 21
    Last Post: 19th May 2006, 10:52

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.