Results 1 to 10 of 10

Thread: clean with transparent color

  1. #1
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default clean with transparent color

    Hi,
    I have a custom Widget where I reimplement paintEvent in order to perform custom drawing, now I'm trying in some particular situation to clean all the previous drawing operation, so I'd like to refill all the widgets with a transparent brush, but when doing that I still see all the old drawings, what can I do?

    thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: clean with transparent color

    Call update() so that a paint event gets scheduled. Then just don't draw anything in paintEvent(). Any "previous drawings" aren't buffered. You must be either drawing them in the paintEvent() or the paintEvent() doesn't get even called..
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clean with transparent color

    thanks for replying,
    well, I just thought there was some way to have "transparent paint" which helps in repaint operations, I tried with Composition mode but without success.
    thanks again

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: clean with transparent color

    Quote Originally Posted by Lele
    well, I just thought there was some way to have "transparent paint" which helps in repaint operations, I tried with Composition mode but without success.
    Child widgets are transparent by default in Qt 4.1 and later. You can get transparent brushes and pens by constructing them with a QColor with an appropriate alpha-channel.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: clean with transparent color

    Or using Qt::transparent

    QPainter paint;
    paint.setBrush(Qt::transparent);

  6. #6
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clean with transparent color

    Thank was my first try but it doesn't clean what I painted before

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: clean with transparent color

    Ah, now I understand what you are saying. You're drawing something in the paintevent and then later in that same event you want to erase it back to transparent. Since the widget is capable of being transparent (since it is at the start of your paintevent), I would suspect that this is somehow possible, but I don't know exactly how. You could try having a look at some of the functions for setting the background mode.

    But the better question to ask is, if there are some situations which require a transparent widget, then why don't you detect this at the start of the paintevent before drawing anything? It will be faster since you're not doing unnecessary drawing and makes this whole question irrelevant.

  8. #8
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clean with transparent color

    That's exactly what I mean, any tips on that or some workaround?
    thanks again

  9. #9
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clean with transparent color

    I do have exactly the same problem.

    Painting with a transparent pen doesn't help (as it paints over the existing image)

    and there is only a QPainter::eraseRect

    thanks,
    niko

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

    Default Re: clean with transparent color

    Use composition mode QPainter::CompositionMode_Clear.

  11. The following user says thank you to wysota for this useful post:

    niko (1st November 2007)

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51
  2. 8bit Color
    By Rayven in forum Qt Programming
    Replies: 4
    Last Post: 10th August 2006, 19:19
  3. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36
  4. Replies: 1
    Last Post: 5th April 2006, 16:44
  5. Backgound color of QWidget
    By jnana in forum Qt Programming
    Replies: 15
    Last Post: 21st March 2006, 20:08

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.