Results 1 to 13 of 13

Thread: 2 Questions about QPainter

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question 2 Questions about QPainter

    Hi all, I'm using Qt4.1 on WindowsXP. I've got 2 questions about QPainter class:
    1) I want to know if it's possible and, in that case, how to paint in OR mode: painting under a surface that has been painted before. I need it because I've implemented a rubberband to select rectangular areas of an image. This is the process: first of all, I paint the image with drawImage function. After,as the rubberband changes its size or position, I want to delete the "old" rubberband painting the original portion of the image where it was the rubberband painted under the image. Finally I paint the "new" rubberband in the current position with drawRect. All this process is done in the paintEvent method of the widget that I use to paint under.
    2) I have noticed that painting an image of 8 bits/pixel (a grayscsale image, for example) with drawImage function is much more slower that painting the same image with 32 bits/pixel (with equal r, g, and b channel for the case of grayscale images) Really strange. Anybody colud tell me what could be the cause? Maybe before drawing the image, qPainter forces the resolution, for some strange reason, to 32 bits/pixel if it's not the real resolution of the image? I don't know it's just a supposition...

    Thanks.
    Last edited by SkripT; 20th February 2006 at 18:27.

  2. #2
    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: 2 Questions about QPainter

    Quote Originally Posted by SkripT
    Hi all, I'm using Qt4.1 on WindowsXP. I've got 2 questions about QPainter class:
    1) I want to know if it's possible and, in that case, how to paint in OR mode: painting under a surface that has been painted before. I need it because I've implemented a rubberband to select rectangular areas of an image. This is the process: first of all, I paint the image with drawImage function. After,as the rubberband changes its size or position, I want to delete the "old" rubberband painting the original portion of the image where it was the rubberband painted under the image. Finally I paint the "new" rubberband in the current position with drawRect. All this process is done in the paintEvent method of the widget that I use to paint under.
    You should be able to achieve it using QPainter::setCompositionMode.

    2) I have noticed that painting an image of 8 bits/pixel (a grayscsale image, for example) with drawImage function is much more slower that painting the same image with 32 bits/pixel (with equal r, g, and b channel for the case of grayscale images) Really strange. Anybody colud tell me what could be the cause? Maybe before drawing the image, qPainter forces the resolution, for some strange reason, to 32 bits/pixel if it's not the real resolution of the image? I don't know it's just a supposition...
    That's probably because the image has to be remapped to the painter's number of planes (32b) (and it has to be copied to do that) which is a lengthy process.

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Hi, relating to my question number 1, I've tried different Composition Modes but the result is always the same: the surface where I paint is always cleared, so only appears what I've painted on the last time Here's a simplified version of the code that I use:

    Qt Code:
    1. void FotoEditorFotos::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter;
    4. painter.begin(this);
    5.  
    6. if (rectABorrar.isNull())
    7. {
    8. // Paint all the image for the first time centered on the widget
    9. int rectW = arrodonirValor(imatge.width() * escala);
    10. int rectH = arrodonirValor(imatge.height() * escala);
    11. rectFoto.setRect((width() >> 1) - (rectW >> 1), (height() >> 1) - (rectH >> 1), rectW, rectH);
    12.  
    13. painter.drawImage(rectFoto, imatge);
    14. }
    15. else
    16. {
    17. // "rectSeleccio" defines the old position and size (geometry) of the rubberband and needs to be deleted with the original portion of the image, defined by "rectABorrar"
    18. painter.setCompositionMode(QPainter::CompositionMode_Destination);//I don't know if this is the Composition Mode that I should use????
    19. painter.drawImage(rectSeleccio, imatge, rectABorrar);
    20.  
    21. rectABorrar.setRect(-1, -1, 0, 0);
    22. }
    23.  
    24. // Code to Paint the rubberband.........
    25.  
    26. painter.end()
    27. }
    To copy to clipboard, switch view to plain text mode 

    Anybody could tell me where's the mistake? Thanks.
    Last edited by SkripT; 21st February 2006 at 10:27.

  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: 2 Questions about QPainter

    Did you try QPainter::CompositionMode_Xor ?

    BTW. Are you aware that the rubber band has its own implementation built into Qt?

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Quote Originally Posted by wysota
    Did you try QPainter::CompositionMode_Xor ?
    Yes but always clears the background, too. Very strange.

    Quote Originally Posted by wysota
    BTW. Are you aware that the rubber band has its own implementation built into Qt?
    Yes I know that exists, but It's not useful for my case. I find it too simple.
    Last edited by SkripT; 21st February 2006 at 11:48.

  6. #6
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Anybody suggests me something that could explain why the background is cleared everytime that I try to delete the rubberband with the code above? I'm a little worried
    Last edited by SkripT; 21st February 2006 at 15:41.

  7. #7
    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: 2 Questions about QPainter

    Does the Qt example which demonstrates different composite modes work for you?

  8. #8
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Quote Originally Posted by wysota
    Does the Qt example which demonstrates different composite modes work for you?
    Sorry wysota, could you tell me the name of this example, please?

    Althought, maybe the problem that I have is that I paint in the paintEvent method and maybe, after calling to repaint, the background is cleared automaticly or something

  9. #9
    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: 2 Questions about QPainter

    Quote Originally Posted by SkripT
    Sorry wysota, could you tell me the name of this example, please?
    demos/composition.

  10. #10
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    wysota I've been looking the demo and I've noticed two main differences: they dont' use begin and end and they don't' paint in the paintEvent method (I think). I dont' know if these are the causes for my code not to work. But anyway I've seen that they repaint all the image everytime to delete the "old circle". And here's my question: do you think that painting all in a buffer(they use a qImage) and later paint this buffer on the destination widget (like a double buffering) is faster that paint every object to be drawn directly on the destination widget?? Thanks
    Last edited by SkripT; 22nd February 2006 at 09:36.

  11. #11
    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: 2 Questions about QPainter

    I think the reason may be that different platforms use different paint enigines and probably not all of them support composing. Probably that's why they used qImage, as it uses the raster engine which probably has composing capabilities built in. Otherwise the demo might not work on all systems. For example Windows uses the rastering engine by default too, while X11 uses PostScript and Mac uses QuickDraw. Additionaly some platform support may be needed for composite to work on different renderers (like the COMPOSITE extension to X11).

  12. #12
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Ok thanks a lot

  13. #13
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QPainter

    Hi again, relating with my first question, I think that's impossible to paint under a widget without clearing the background in the way that I want. I've tried different ways: setting transparent background, different composition modes, etc. but no success: everytime clears the background. The only solution is to paint again all the image everytime that the rubberband changes its position or size. But as you can see, this is very inefficient specially if the image has a big size. The problem is that the rubberband is painted with some delay since the mouse cursor and it's a bit annoying. I'm thinking in other solutions: does anybody knows a way to paint the image in background mode and in a specified fixed position and size like if it was permanently "painted" on the widget? So it releases of painting everytime the image. I think that a QLabel wouldn't be useful because it wouldn't be able to paint the rubberband under the label...
    Last edited by SkripT; 22nd February 2006 at 15:14.

Similar Threads

  1. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 09:42
  2. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  3. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 14:48
  4. Replies: 7
    Last Post: 20th March 2006, 20:03
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.